@sodax/dapp-kit 0.0.1-rc.2 → 0.0.1-rc.21
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/LICENSE +21 -0
- package/README.md +30 -37
- package/dist/contexts/index.d.ts +4 -1
- package/dist/contexts/index.d.ts.map +1 -1
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/hooks/mm/index.d.ts +3 -1
- package/dist/hooks/mm/index.d.ts.map +1 -1
- package/dist/hooks/mm/useBorrow.d.ts +13 -4
- package/dist/hooks/mm/useBorrow.d.ts.map +1 -1
- package/dist/hooks/mm/useMMAllowance.d.ts +26 -0
- package/dist/hooks/mm/useMMAllowance.d.ts.map +1 -0
- package/dist/hooks/mm/useMMApprove.d.ts +27 -0
- package/dist/hooks/mm/useMMApprove.d.ts.map +1 -0
- package/dist/hooks/mm/useRepay.d.ts +13 -4
- package/dist/hooks/mm/useRepay.d.ts.map +1 -1
- package/dist/hooks/mm/useReservesData.d.ts +19 -0
- package/dist/hooks/mm/useReservesData.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesHumanized.d.ts +21 -0
- package/dist/hooks/mm/useReservesHumanized.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesList.d.ts +18 -0
- package/dist/hooks/mm/useReservesList.d.ts.map +1 -0
- package/dist/hooks/mm/useReservesUsdFormat.d.ts +23 -0
- package/dist/hooks/mm/useReservesUsdFormat.d.ts.map +1 -0
- package/dist/hooks/mm/useSupply.d.ts +4 -2
- package/dist/hooks/mm/useSupply.d.ts.map +1 -1
- package/dist/hooks/mm/useUserFormattedSummary.d.ts +21 -0
- package/dist/hooks/mm/useUserFormattedSummary.d.ts.map +1 -0
- package/dist/hooks/mm/useUserReservesData.d.ts +19 -8
- package/dist/hooks/mm/useUserReservesData.d.ts.map +1 -1
- package/dist/hooks/mm/useWithdraw.d.ts +11 -4
- package/dist/hooks/mm/useWithdraw.d.ts.map +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts +1 -1
- package/dist/hooks/provider/useHubProvider.d.ts.map +1 -1
- package/dist/hooks/provider/useSpokeProvider.d.ts +16 -2
- package/dist/hooks/provider/useSpokeProvider.d.ts.map +1 -1
- package/dist/hooks/shared/index.d.ts +1 -2
- package/dist/hooks/shared/index.d.ts.map +1 -1
- package/dist/hooks/shared/useEstimateGas.d.ts +4 -0
- package/dist/hooks/shared/useEstimateGas.d.ts.map +1 -0
- package/dist/hooks/swap/index.d.ts +4 -1
- package/dist/hooks/swap/index.d.ts.map +1 -1
- package/dist/hooks/swap/useCancelSwap.d.ts +29 -0
- package/dist/hooks/swap/useCancelSwap.d.ts.map +1 -0
- package/dist/hooks/swap/useQuote.d.ts +4 -4
- package/dist/hooks/swap/useQuote.d.ts.map +1 -1
- package/dist/hooks/swap/useStatus.d.ts +3 -3
- package/dist/hooks/swap/useStatus.d.ts.map +1 -1
- package/dist/hooks/swap/useSwap.d.ts +29 -0
- package/dist/hooks/swap/useSwap.d.ts.map +1 -0
- package/dist/hooks/swap/useSwapAllowance.d.ts +23 -0
- package/dist/hooks/swap/useSwapAllowance.d.ts.map +1 -0
- package/dist/hooks/swap/useSwapApprove.d.ts +25 -0
- package/dist/hooks/swap/useSwapApprove.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +244 -189
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +238 -186
- package/dist/index.mjs.map +1 -1
- package/dist/providers/SodaxProvider.d.ts +4 -2
- package/dist/providers/SodaxProvider.d.ts.map +1 -1
- package/dist/types.d.ts +17 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +5 -6
- package/src/contexts/index.ts +4 -1
- package/src/core/index.ts +5 -33
- package/src/hooks/mm/index.ts +3 -1
- package/src/hooks/mm/useBorrow.ts +20 -10
- package/src/hooks/mm/useMMAllowance.ts +55 -0
- package/src/hooks/mm/useMMApprove.ts +67 -0
- package/src/hooks/mm/useRepay.ts +20 -10
- package/src/hooks/mm/useReservesData.ts +30 -0
- package/src/hooks/mm/useReservesHumanized.ts +30 -0
- package/src/hooks/mm/useReservesList.ts +29 -0
- package/src/hooks/mm/useReservesUsdFormat.ts +38 -0
- package/src/hooks/mm/useSupply.ts +9 -6
- package/src/hooks/mm/useUserFormattedSummary.ts +54 -0
- package/src/hooks/mm/useUserReservesData.ts +30 -48
- package/src/hooks/mm/useWithdraw.ts +17 -11
- package/src/hooks/provider/useHubProvider.ts +2 -20
- package/src/hooks/provider/useSpokeProvider.ts +91 -6
- package/src/hooks/shared/index.ts +1 -2
- package/src/hooks/shared/useEstimateGas.ts +18 -0
- package/src/hooks/swap/index.ts +4 -1
- package/src/hooks/swap/useCancelSwap.ts +44 -0
- package/src/hooks/swap/useQuote.ts +5 -5
- package/src/hooks/swap/useStatus.ts +3 -3
- package/src/hooks/swap/{useCreateIntentOrder.ts → useSwap.ts} +16 -18
- package/src/hooks/swap/useSwapAllowance.ts +47 -0
- package/src/hooks/swap/useSwapApprove.ts +68 -0
- package/src/index.ts +1 -0
- package/src/providers/SodaxProvider.tsx +22 -5
- package/src/types.ts +22 -0
- package/dist/hooks/mm/useHubWalletAddress.d.ts +0 -24
- package/dist/hooks/mm/useHubWalletAddress.d.ts.map +0 -1
- package/dist/hooks/shared/useAllowance.d.ts +0 -3
- package/dist/hooks/shared/useAllowance.d.ts.map +0 -1
- package/dist/hooks/shared/useApprove.d.ts +0 -10
- package/dist/hooks/shared/useApprove.d.ts.map +0 -1
- package/dist/hooks/swap/useCreateIntentOrder.d.ts +0 -33
- package/dist/hooks/swap/useCreateIntentOrder.d.ts.map +0 -1
- package/src/hooks/mm/useHubWalletAddress.ts +0 -49
- package/src/hooks/shared/useAllowance.ts +0 -31
- package/src/hooks/shared/useApprove.ts +0 -53
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/contexts/index.ts","../src/hooks/shared/useSodaxContext.ts","../src/hooks/provider/useSpokeProvider.ts","../src/hooks/shared/useAllowance.ts","../src/hooks/shared/useApprove.ts","../src/hooks/provider/useHubProvider.ts","../src/hooks/mm/useBorrow.ts","../src/hooks/mm/useRepay.ts","../src/hooks/mm/useSupply.ts","../src/hooks/mm/useWithdraw.ts","../src/core/index.ts","../src/hooks/mm/useHubWalletAddress.ts","../src/hooks/mm/useUserReservesData.ts","../src/hooks/swap/useQuote.ts","../src/hooks/swap/useCreateIntentOrder.ts","../src/hooks/swap/useStatus.ts","../src/providers/SodaxProvider.tsx"],"names":["parseUnits","getXChainType","useMemo","useMutation","useQuery","useWalletProvider"],"mappings":";;;;;;;AAQO,IAAM,YAAA,GAAe,cAAuC,IAAI,CAAA;ACChE,IAAM,kBAAkB,MAAwB;AACrD,EAAM,MAAA,OAAA,GAAU,WAAW,YAAY,CAAA;AACvC,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,qDAAqD,CAAA;AAAA;AAEvE,EAAO,OAAA,OAAA;AACT;ACJO,SAAS,iBAAiB,YAA4B,EAAA;AAC3D,EAAM,MAAA,UAAA,GAAa,cAAc,YAAY,CAAA;AAC7C,EAAM,MAAA,cAAA,GAAiB,kBAAkB,YAAY,CAAA;AACrD,EAAM,MAAA,aAAA,GAAgB,QAAQ,MAAM;AAClC,IAAI,IAAA,CAAC,gBAAuB,OAAA,MAAA;AAC5B,IAAA,IAAI,eAAe,KAAO,EAAA;AACxB,MAAA,OAAO,IAAI,gBAAA;AAAA,QACT,cAAA;AAAA,QACA,iBAAiB,YAAY;AAAA,OAC/B;AAAA;AAEF,IAAA,IAAI,eAAe,KAAO,EAAA;AACxB,MAAA,OAAO,IAAI,gBAAA;AAAA,QACT,iBAAiB,YAAY,CAAA;AAAA,QAC7B;AAAA,OACF;AAAA;AAEF,IAAO,OAAA,MAAA;AAAA,GACN,EAAA,CAAC,cAAgB,EAAA,UAAA,EAAY,YAAY,CAAC,CAAA;AAE7C,EAAO,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,CAAA;AACH;AChCO,IAAM,gBAAgB,CAAC,EAAE,UAAU,OAAU,GAAA,KAAA,EAAO,QAA+C,KAAA;AACxG,EAAM,MAAA,KAAA,GAAQ,IAAI,KAAA,CAAM,MAAM,CAAA;AAE9B,EAAO,uBAAA,KAAA,CAAA,aAAA,CAAC,aAAa,QAAb,EAAA,EAAsB,OAAO,EAAE,KAAA,EAAO,OAAQ,EAAA,EAAA,EAAI,QAAS,CAAA;AACrE","file":"index.mjs","sourcesContent":["import { createContext } from 'react';\nimport type { Sodax } from '@sodax/sdk';\n\nexport interface SodaxContextType {\n sodax: Sodax;\n testnet: boolean;\n}\n\nexport const SodaxContext = createContext<SodaxContextType | null>(null);\n","import { SodaxContext, type SodaxContextType } from '@/contexts';\nimport { useContext } from 'react';\n\n/**\n * Hook to access the Sodax context which provides access to the Sodax SDK instance and chain configuration\n * @throws {Error} If used outside of a SodaxProvider\n * @returns {SodaxContextType} The Sodax context containing SDK instance and configuration\n */\n\nexport const useSodaxContext = (): SodaxContextType => {\n const context = useContext(SodaxContext);\n if (!context) {\n throw new Error('useSodaxContext must be used within a SodaxProvider');\n }\n return context;\n};\n","import {\n EvmSpokeProvider,\n spokeChainConfig,\n type SuiSpokeChainConfig,\n SuiSpokeProvider,\n type EvmSpokeChainConfig,\n} from '@sodax/sdk';\nimport type { IEvmWalletProvider, ISuiWalletProvider, SpokeChainId } from '@sodax/types';\nimport { getXChainType, useWalletProvider } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\n\nexport function useSpokeProvider(spokeChainId: SpokeChainId) {\n const xChainType = getXChainType(spokeChainId);\n const walletProvider = useWalletProvider(spokeChainId);\n const spokeProvider = useMemo(() => {\n if (!walletProvider) return undefined;\n if (xChainType === 'EVM') {\n return new EvmSpokeProvider(\n walletProvider as IEvmWalletProvider,\n spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,\n );\n }\n if (xChainType === 'SUI') {\n return new SuiSpokeProvider(\n spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,\n walletProvider as ISuiWalletProvider,\n );\n }\n return undefined;\n }, [walletProvider, xChainType, spokeChainId]);\n\n return spokeProvider;\n}\n","import { useQuery } from '@tanstack/react-query';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { parseUnits } from 'viem';\n\nexport function useAllowance(token: XToken, amount: string) {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n\n return useQuery({\n queryKey: ['allowance', token.address, amount],\n queryFn: async () => {\n if (!spokeProvider) {\n return false;\n }\n const allowance = await sodax.moneyMarket.isAllowanceValid(\n {\n token: token.address,\n amount: parseUnits(amount, token.decimals),\n },\n spokeProvider,\n );\n if (allowance.ok) {\n return allowance.value;\n }\n return false;\n },\n enabled: !!spokeProvider,\n });\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport type { SpokeChainId, XToken } from '@sodax/types';\nimport { parseUnits } from 'viem';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type { Address } from '@sodax/sdk';\n\ninterface UseApproveReturn {\n approve: (amount: string) => Promise<boolean>;\n isLoading: boolean;\n error: Error | null;\n resetError: () => void;\n}\n\nexport function useApprove(token: XToken): UseApproveReturn {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(token.xChainId as SpokeChainId);\n const queryClient = useQueryClient();\n\n const {\n mutateAsync: approve,\n isPending,\n error,\n reset: resetError,\n } = useMutation({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n const allowance = await sodax.moneyMarket.approve(\n token.address as Address,\n parseUnits(amount, token.decimals),\n spokeProvider.chainConfig.addresses.assetManager as Address,\n spokeProvider,\n );\n if (!allowance.ok) {\n throw new Error('Failed to approve tokens');\n }\n return allowance.ok;\n },\n onSuccess: () => {\n // Invalidate allowance query to refetch the new allowance\n queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });\n },\n });\n\n return {\n approve,\n isLoading: isPending,\n error: error as Error | null,\n resetError,\n };\n}\n","import { EvmHubProvider, getHubChainConfig, type HubChainId } from '@sodax/sdk';\nimport { getXChainType } from '@sodax/wallet-sdk';\nimport { useMemo } from 'react';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useHubProvider(): EvmHubProvider | undefined {\n const { sodax } = useSodaxContext();\n const hubChainId = sodax.config?.hubProviderConfig?.chainConfig.chain.id;\n const hubRpcUrl = sodax.config?.hubProviderConfig?.hubRpcUrl;\n const xChainType = getXChainType(hubChainId);\n const hubProvider = useMemo(() => {\n if (xChainType === 'EVM' && hubChainId && hubRpcUrl) {\n const hubChainCfg = getHubChainConfig(hubChainId);\n\n if (!hubChainCfg) return undefined;\n\n return new EvmHubProvider({\n hubRpcUrl: hubRpcUrl,\n chainConfig: hubChainCfg,\n });\n }\n return undefined;\n }, [xChainType, hubChainId, hubRpcUrl]);\n\n return hubProvider;\n}\n","import type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport type { SpokeChainId } from '@sodax/sdk';\ninterface BorrowResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for borrowing tokens from the Sodax money market.\n *\n * This hook provides functionality to borrow tokens from the money market protocol,\n * handling the entire borrow process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: borrow, isPending, error } = useBorrow(hubToken, spokeChainId);\n * await borrow('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useBorrow(hubToken: XToken, spokeChainId: ChainId): UseMutationResult<BorrowResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<BorrowResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.borrowAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to borrow tokens');\n }\n\n console.log('Borrow transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface RepayResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for repaying borrowed tokens to the Sodax money market.\n *\n * This hook provides functionality to repay borrowed tokens back to the money market protocol,\n * handling the entire repayment process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: repay, isPending, error } = useRepay(hubToken, spokeChainId);\n * await repay('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useRepay(hubToken: XToken, spokeChainId: ChainId): UseMutationResult<RepayResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<RepayResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.repayAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to repay tokens');\n }\n\n console.log('Repay transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface SupplyResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for supplying tokens to the Sodax money market.\n *\n * This hook provides functionality to supply tokens to the money market protocol,\n * handling the entire supply process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.\n *\n * @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the supply transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: supply, isPending, error } = useSupply(spokeToken);\n * await supply('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n */\nexport function useSupply(spokeToken: XToken): UseMutationResult<SupplyResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeToken.xChainId as SpokeChainId);\n\n return useMutation<SupplyResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.supplyAndSubmit(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to supply tokens');\n }\n\n console.log('Supply transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeChainId } from '@sodax/sdk';\nimport type { ChainId, XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface WithdrawResponse {\n ok: true;\n value: [`0x${string}`, `0x${string}`];\n}\n\n/**\n * Hook for withdrawing supplied tokens from the Sodax money market.\n *\n * This hook provides functionality to withdraw previously supplied tokens from the money market protocol,\n * handling the entire withdrawal process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @example\n * ```typescript\n * const { mutateAsync: withdraw, isPending, error } = useWithdraw(hubToken, spokeChainId);\n * await withdraw('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useWithdraw(\n hubToken: XToken,\n spokeChainId: ChainId,\n): UseMutationResult<WithdrawResponse, Error, string> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);\n\n return useMutation<WithdrawResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.withdrawAndSubmit(\n {\n token: hubToken.address,\n amount: parseUnits(amount, hubToken.decimals),\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to withdraw tokens');\n }\n\n console.log('Withdraw transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { XToken, ChainId } from '@sodax/types';\n\nimport { hubAssets } from '@sodax/sdk';\n\nexport const allXTokens: XToken[] = [];\n\nObject.keys(hubAssets).forEach(xChainId => {\n const tokens = hubAssets[xChainId];\n\n Object.keys(tokens).forEach(tokenAddress => {\n const token = tokens[tokenAddress];\n allXTokens.push({\n xChainId: xChainId as ChainId,\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: tokenAddress,\n });\n\n allXTokens.push({\n xChainId: 'sonic',\n symbol: token.symbol,\n name: token.name,\n decimals: token.decimal,\n address: token.vault,\n });\n });\n});\n\nexport const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {\n const tokens = hubAssets[spokeChainId];\n\n const token = Object.keys(tokens).find(tokenAddress => tokens[tokenAddress].vault === vault);\n\n if (!token) {\n throw new Error('Token not found');\n }\n\n return token;\n};\n","import { type EvmHubProvider, EvmWalletAbstraction, type SpokeChainId } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for retrieving the hub wallet address for a given spoke chain and address.\n *\n * This hook fetches the hub wallet address associated with a user's address on a specific spoke chain.\n * It uses the EvmWalletAbstraction to query the hub wallet address from the hub provider.\n *\n * @param spokeChainId - The chain ID of the spoke chain\n * @param address - The user's address on the spoke chain\n * @param hubProvider - The hub provider instance\n *\n * @returns {UseQueryResult<string | null>} A query result object containing:\n * - data: The hub wallet address or null if not found\n * - isLoading: Boolean indicating if the query is in progress\n * - error: Error object if the query failed, null otherwise\n *\n * @example\n * ```typescript\n * const { data: hubWalletAddress, isLoading, error } = useHubWalletAddress(spokeChainId, address, hubProvider);\n * ```\n */\n\nexport function useHubWalletAddress(\n spokeChainId: SpokeChainId,\n address: string | undefined,\n hubProvider: EvmHubProvider,\n): UseQueryResult<string | null> {\n return useQuery({\n queryKey: ['hubWallet', spokeChainId, address],\n queryFn: async () => {\n if (!address) return null;\n\n try {\n const hubWalletAddress = await EvmWalletAbstraction.getUserHubWalletAddress(\n spokeChainId,\n address as `0x${string}`,\n hubProvider,\n );\n return hubWalletAddress;\n } catch (error) {\n console.log('error', error);\n return null;\n }\n },\n enabled: !!address && !!hubProvider,\n });\n}\n","import { allXTokens } from '@/core';\nimport { getMoneyMarketConfig, type EvmHubProvider } from '@sodax/sdk';\nimport type { HubChainId, SpokeChainId } from '@sodax/types';\nimport { useXAccount, useWalletProvider } from '@sodax/wallet-sdk';\nimport type { ChainId } from '@sodax/types';\nimport { useQuery } from '@tanstack/react-query';\nimport { useHubProvider } from '../provider/useHubProvider';\nimport { useHubWalletAddress } from './useHubWalletAddress';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useUserReservesData(spokeChainId: ChainId) {\n const { sodax } = useSodaxContext();\n const hubChainId = (sodax.config?.hubProviderConfig?.chainConfig.chain.id ?? 'sonic') as HubChainId;\n const hubWalletProvider = useWalletProvider(hubChainId);\n const hubProvider = useHubProvider();\n const { address } = useXAccount(spokeChainId);\n const { data: hubWalletAddress } = useHubWalletAddress(\n spokeChainId as SpokeChainId,\n address,\n hubProvider as EvmHubProvider,\n );\n\n const { data: userReserves } = useQuery({\n queryKey: ['userReserves', hubWalletAddress],\n queryFn: async () => {\n if (!hubWalletProvider) {\n return;\n }\n\n if (!hubWalletAddress) {\n return;\n }\n\n const moneyMarketConfig = getMoneyMarketConfig(hubChainId);\n try {\n const [res] = await sodax.moneyMarket.getUserReservesData(\n hubWalletAddress as `0x${string}`,\n moneyMarketConfig.uiPoolDataProvider,\n moneyMarketConfig.poolAddressesProvider,\n );\n\n return res?.map(r => {\n return {\n ...r,\n token: allXTokens.find(t => t.address === r.underlyingAsset),\n };\n });\n } catch (error) {\n console.log('error', error);\n return;\n }\n },\n enabled: !!address && !!hubWalletProvider && !!hubWalletAddress,\n refetchInterval: 5000,\n });\n\n return userReserves;\n}\n","import type { IntentErrorResponse, IntentQuoteRequest, IntentQuoteResponse, Result } from '@sodax/sdk';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for fetching a quote for an intent-based swap.\n *\n * This hook provides real-time quote data for an intent-based swap.\n *\n * @param {IntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.\n *\n * @returns {UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The quote result from the solver\n * - isLoading: Boolean indicating if the quote is being fetched\n * - error: Error object if the quote request failed\n * - refetch: Function to manually trigger a quote refresh\n *\n * @example\n * ```typescript\n * const { data: quote, isLoading } = useQuote({\n * token_src: '0x...',\n * token_src_blockchain_id: '1',\n * token_dst: '0x...',\n * token_dst_blockchain_id: '2',\n * amount: '1000000000000000000',\n * quote_type: 'exact_input',\n * });\n *\n * if (isLoading) return <div>Loading quote...</div>;\n * if (quote) {\n * console.log('Quote received:', quote);\n * }\n * ```\n *\n * @remarks\n * - The quote is automatically refreshed every 3 seconds\n * - The query is disabled when payload is undefined\n * - Uses React Query for efficient caching and state management\n */\nexport const useQuote = (\n payload: IntentQuoteRequest | undefined,\n): UseQueryResult<Result<IntentQuoteResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [payload],\n queryFn: async () => {\n if (!payload) {\n return undefined;\n }\n return sodax.solver.getQuote(payload);\n },\n enabled: !!payload,\n refetchInterval: 3000,\n });\n};\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type {\n CreateIntentParams,\n SpokeChainId,\n IntentExecutionResponse,\n Result,\n IntentSubmitErrorCode,\n Intent,\n PacketData,\n IntentSubmitError,\n} from '@sodax/sdk';\nimport { useSpokeProvider } from '../provider/useSpokeProvider';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\ntype CreateIntentResult = Result<\n [IntentExecutionResponse, Intent, PacketData],\n IntentSubmitError<IntentSubmitErrorCode>\n>;\n\n/**\n * Hook for creating and submitting an intent order for cross-chain swaps.\n * Uses React Query's useMutation for better state management and caching.\n *\n * @param {SpokeChainId} chainId - The source chain ID where the swap will originate\n * @returns {UseMutationResult} Mutation result object containing mutation function and state\n *\n * @example\n * ```typescript\n * const { mutateAsync: createIntent, isPending } = useCreateIntentOrder('0xa4b1.arbitrum');\n *\n * const handleSwap = async () => {\n * const result = await createIntent({\n * token_src: '0x...',\n * token_src_blockchain_id: 'arbitrum',\n * token_dst: '0x...',\n * token_dst_blockchain_id: 'polygon',\n * amount: '1000000000000000000',\n * min_output_amount: '900000000000000000'\n * });\n * };\n * ```\n */\nexport function useCreateIntentOrder(\n chainId: SpokeChainId,\n): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {\n const { sodax } = useSodaxContext();\n const spokeProvider = useSpokeProvider(chainId);\n\n return useMutation<CreateIntentResult, Error, CreateIntentParams>({\n mutationFn: async (params: CreateIntentParams) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n return sodax.solver.createAndSubmitIntent(params, spokeProvider);\n },\n });\n}\n","import type { Hex, IntentErrorResponse, IntentStatusResponse, Result } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\n/**\n * Hook for monitoring the status of an intent-based swap.\n *\n * This hook provides real-time status updates for an intent-based swap transaction.\n *\n * @param {Hex} intent_tx_hash - The transaction hash of the intent order on the hub chain\n *\n * @returns {UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined>} A query result object containing:\n * - data: The status result from the solver\n * - isLoading: Boolean indicating if the status is being fetched\n * - error: Error object if the status request failed\n * - refetch: Function to manually trigger a status refresh\n *\n * @example\n * ```typescript\n * const { data: status, isLoading } = useStatus('0x...');\n *\n * if (isLoading) return <div>Loading status...</div>;\n * if (status?.ok) {\n * console.log('Status:', status.value);\n * }\n * ```\n *\n * @remarks\n * - The status is automatically refreshed every 3 seconds\n * - Uses React Query for efficient caching and state management\n */\n\nexport const useStatus = (\n intent_tx_hash: Hex,\n): UseQueryResult<Result<IntentStatusResponse, IntentErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [intent_tx_hash],\n queryFn: async () => {\n return sodax.solver.getStatus({ intent_tx_hash });\n },\n refetchInterval: 3000, // 3s\n });\n};\n","import type { ReactNode, ReactElement } from 'react';\nimport { Sodax, type SodaxConfig } from '@sodax/sdk';\nimport { SodaxContext } from '@/contexts';\nimport React from 'react';\n\ninterface SodaxProviderProps {\n children: ReactNode;\n testnet?: boolean;\n config: SodaxConfig;\n}\n\nexport const SodaxProvider = ({ children, testnet = false, config }: SodaxProviderProps): ReactElement => {\n const sodax = new Sodax(config);\n\n return <SodaxContext.Provider value={{ sodax, testnet }}>{children}</SodaxContext.Provider>;\n};\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/contexts/index.ts","../src/hooks/shared/useSodaxContext.ts","../src/hooks/shared/useEstimateGas.ts","../src/hooks/provider/useHubProvider.ts","../src/hooks/provider/useSpokeProvider.ts","../src/hooks/mm/useBorrow.ts","../src/hooks/mm/useRepay.ts","../src/hooks/mm/useSupply.ts","../src/hooks/mm/useWithdraw.ts","../src/hooks/mm/useUserReservesData.ts","../src/hooks/mm/useReservesData.ts","../src/hooks/mm/useMMAllowance.ts","../src/hooks/mm/useMMApprove.ts","../src/hooks/swap/useQuote.ts","../src/hooks/swap/useSwap.ts","../src/hooks/swap/useStatus.ts","../src/hooks/swap/useSwapAllowance.ts","../src/hooks/swap/useSwapApprove.ts","../src/hooks/swap/useCancelSwap.ts","../src/providers/SodaxProvider.tsx","../src/core/index.ts"],"names":["useMutation","parseUnits","useQuery","useQueryClient","params","useMemo"],"mappings":";;;;;;AAWO,IAAM,YAAA,GAAe,cAAuC,IAAI,CAAA;ACFhE,IAAM,kBAAkB,MAAwB;AACrD,EAAM,MAAA,OAAA,GAAU,WAAW,YAAY,CAAA;AACvC,EAAA,IAAI,CAAC,OAAS,EAAA;AACZ,IAAM,MAAA,IAAI,MAAM,qDAAqD,CAAA;AAAA;AAEvE,EAAO,OAAA,OAAA;AACT;ACZO,SAAS,eACd,aAC8E,EAAA;AAC9E,EAAA,OAAO,WAAuE,CAAA;AAAA,IAC5E,UAAA,EAAY,OAAO,KAAiC,KAAA;AAClD,MAAA,IAAI,CAAC,aAAe,EAAA;AAClB,QAAM,MAAA,IAAI,MAAM,4BAA4B,CAAA;AAAA;AAG9C,MAAA,MAAM,QAAW,GAAA,MAAM,YAAa,CAAA,WAAA,CAAY,OAAO,aAAa,CAAA;AAEpE,MAAO,OAAA,QAAA;AAAA;AACT,GACD,CAAA;AACH;;;ACdO,SAAS,cAA6C,GAAA;AAC3D,EAAM,MAAA,EAAE,WAAY,EAAA,GAAI,eAAgB,EAAA;AAExC,EAAO,OAAA,WAAA;AACT;ACuCO,SAAS,gBAAA,CACd,cACA,cAC2B,EAAA;AAC3B,EAAM,MAAA,EAAE,S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A,GAAS,UAAU,YAAY,CAAA;AACrC,EAAA,MAAM,OAAU,GAAA,MAAA,CAAO,IAAK,CAAA,MAAM,CAAE,CAAA,IAAA;AAAA,IAClC,CAAA,YAAA,KAAgB,OAAO,YAAY,CAAA,CAAE,MAAM,WAAY,EAAA,KAAM,MAAM,WAAY;AAAA,GACjF;AAEA,EAAO,OAAA,OAAA;AACT","file":"index.mjs","sourcesContent":["import { createContext } from 'react';\nimport type { EvmHubProvider, Sodax } from '@sodax/sdk';\nimport type { RpcConfig } from '@/types';\n\nexport interface SodaxContextType {\n sodax: Sodax;\n testnet: boolean;\n hubProvider: EvmHubProvider | undefined;\n rpcConfig: RpcConfig;\n}\n\nexport const SodaxContext = createContext<SodaxContextType | null>(null);\n","import { SodaxContext, type SodaxContextType } from '@/contexts';\nimport { useContext } from 'react';\n\n/**\n * Hook to access the Sodax context which provides access to the Sodax SDK instance and chain configuration\n * @throws {Error} If used outside of a SodaxProvider\n * @returns {SodaxContextType} The Sodax context containing SDK instance and configuration\n */\n\nexport const useSodaxContext = (): SodaxContextType => {\n const context = useContext(SodaxContext);\n if (!context) {\n throw new Error('useSodaxContext must be used within a SodaxProvider');\n }\n return context;\n};\n","import { type GetEstimateGasReturnType, type SpokeProvider, SpokeService, type TxReturnType } from '@sodax/sdk';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\nexport function useEstimateGas<T extends SpokeProvider = SpokeProvider>(\n spokeProvider: T | undefined,\n): UseMutationResult<GetEstimateGasReturnType<T>, Error, TxReturnType<T, true>> {\n return useMutation<GetEstimateGasReturnType<T>, Error, TxReturnType<T, true>>({\n mutationFn: async (rawTx: TxReturnType<T, true>) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await SpokeService.estimateGas(rawTx, spokeProvider);\n\n return response;\n },\n });\n}\n","import type { EvmHubProvider } from '@sodax/sdk';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\nexport function useHubProvider(): EvmHubProvider | undefined {\n const { hubProvider } = useSodaxContext();\n\n return hubProvider;\n}\n","import { useSodaxContext } from '@/index';\nimport {\n EvmSpokeProvider,\n spokeChainConfig,\n type SuiSpokeChainConfig,\n SuiSpokeProvider,\n type EvmSpokeChainConfig,\n IconSpokeProvider,\n type IconSpokeChainConfig,\n InjectiveSpokeProvider,\n type InjectiveSpokeChainConfig,\n StellarSpokeProvider,\n type StellarSpokeChainConfig,\n type SpokeProvider,\n type IWalletProvider,\n SolanaSpokeProvider,\n type SolanaChainConfig,\n SONIC_MAINNET_CHAIN_ID,\n SonicSpokeProvider,\n type SonicSpokeChainConfig,\n} from '@sodax/sdk';\nimport type {\n IEvmWalletProvider,\n IIconWalletProvider,\n ISuiWalletProvider,\n SpokeChainId,\n IInjectiveWalletProvider,\n IStellarWalletProvider,\n ISolanaWalletProvider,\n} from '@sodax/types';\nimport { useMemo } from 'react';\n\n/**\n * Hook to get the appropriate spoke provider based on the chain type.\n * Supports EVM, SUI, ICON and INJECTIVE chains.\n *\n * @param {SpokeChainId | undefined} spokeChainId - The spoke chain ID to get the provider for\n * @param {IWalletProvider | undefined} walletProvider - The wallet provider to use\n * @returns {SpokeProvider | undefined} The appropriate spoke provider instance for the given chain ID, or undefined if invalid/unsupported\n *\n * @example\n * ```tsx\n * // Using a specific SpokeChainId and wallet provider\n * const spokeProvider = useSpokeProvider(spokeChainId, walletProvider);\n * ```\n */\nexport function useSpokeProvider(\n spokeChainId: SpokeChainId | undefined,\n walletProvider?: IWalletProvider | undefined,\n): SpokeProvider | undefined {\n const { rpcConfig } = useSodaxContext();\n const xChainType = spokeChainId ? spokeChainConfig[spokeChainId]?.chain.type : undefined;\n\n const spokeProvider = useMemo(() => {\n if (!walletProvider) return undefined;\n if (!spokeChainId) return undefined;\n if (!xChainType) return undefined;\n if (!rpcConfig) return undefined;\n\n if (xChainType === 'EVM') {\n if (spokeChainId === SONIC_MAINNET_CHAIN_ID) {\n return new SonicSpokeProvider(\n walletProvider as IEvmWalletProvider,\n spokeChainConfig[spokeChainId] as SonicSpokeChainConfig,\n );\n }\n return new EvmSpokeProvider(\n walletProvider as IEvmWalletProvider,\n spokeChainConfig[spokeChainId] as EvmSpokeChainConfig,\n );\n }\n\n if (xChainType === 'SUI') {\n return new SuiSpokeProvider(\n spokeChainConfig[spokeChainId] as SuiSpokeChainConfig,\n walletProvider as ISuiWalletProvider,\n );\n }\n\n if (xChainType === 'ICON') {\n return new IconSpokeProvider(\n walletProvider as IIconWalletProvider,\n spokeChainConfig[spokeChainId] as IconSpokeChainConfig,\n );\n }\n\n if (xChainType === 'INJECTIVE') {\n return new InjectiveSpokeProvider(\n spokeChainConfig[spokeChainId] as InjectiveSpokeChainConfig,\n walletProvider as IInjectiveWalletProvider,\n );\n }\n\n if (xChainType === 'STELLAR') {\n const stellarConfig = spokeChainConfig[spokeChainId] as StellarSpokeChainConfig;\n return new StellarSpokeProvider(walletProvider as IStellarWalletProvider, stellarConfig, {\n horizonRpcUrl: stellarConfig.horizonRpcUrl,\n sorobanRpcUrl: stellarConfig.sorobanRpcUrl,\n });\n }\n\n if (xChainType === 'SOLANA') {\n return new SolanaSpokeProvider(\n walletProvider as ISolanaWalletProvider,\n rpcConfig.solana\n ? ({\n ...spokeChainConfig[spokeChainId],\n rpcUrl: rpcConfig.solana,\n } as SolanaChainConfig)\n : (spokeChainConfig[spokeChainId] as SolanaChainConfig),\n );\n }\n\n return undefined;\n }, [spokeChainId, xChainType, walletProvider, rpcConfig]);\n\n return spokeProvider;\n}\n","import type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport type { SpokeProvider } from '@sodax/sdk';\ninterface BorrowResponse {\n ok: true;\n value: [string, string];\n}\n\n/**\n * Hook for borrowing tokens from the Sodax money market.\n *\n * This hook provides functionality to borrow tokens from the money market protocol,\n * handling the entire borrow process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to borrow from the spoke chain. Must be an XToken with valid address and chain information.\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for the borrow transaction. Must be a valid SpokeProvider instance.\n *\n * @returns {UseMutationResult<BorrowResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the borrow transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);\n * await borrow('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useBorrow(\n spokeToken: XToken,\n spokeProvider: SpokeProvider | undefined,\n): UseMutationResult<BorrowResponse, Error, string> {\n const { sodax } = useSodaxContext();\n\n return useMutation<BorrowResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.borrow(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, 18),\n action: 'borrow',\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to borrow tokens');\n }\n\n console.log('Borrow transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeProvider } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface RepayResponse {\n ok: true;\n value: [string, string];\n}\n\n/**\n * Hook for repaying borrowed tokens to the Sodax money market.\n *\n * This hook provides functionality to repay borrowed tokens back to the money market protocol,\n * handling the entire repayment process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to repay on the spoke chain. Must be an XToken with valid address and chain information.\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for the repay transaction. Must be a valid SpokeProvider instance.\n *\n * @returns {UseMutationResult<RepayResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the repay transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);\n * await repay('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useRepay(\n spokeToken: XToken,\n spokeProvider: SpokeProvider | undefined,\n): UseMutationResult<RepayResponse, Error, string> {\n const { sodax } = useSodaxContext();\n\n return useMutation<RepayResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.repay(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n action: 'repay',\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to repay tokens');\n }\n\n console.log('Repay transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeProvider } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface SupplyResponse {\n ok: true;\n value: [string, string];\n}\n\n/**\n * Hook for supplying tokens to the Sodax money market.\n *\n * This hook provides functionality to supply tokens to the money market protocol,\n * handling the entire supply process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to supply on the spoke chain. Must be an XToken with valid address and chain information.\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for the supply transaction. Must be a valid SpokeProvider instance.\n *\n * @returns {UseMutationResult<SupplyResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the supply transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * - error: Error object if the last transaction failed, null otherwise\n *\n * @example\n * ```typescript\n * const { mutateAsync: supply, isPending, error } = useSupply(spokeToken);\n * await supply('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n */\nexport function useSupply(\n spokeToken: XToken,\n spokeProvider: SpokeProvider | undefined,\n): UseMutationResult<SupplyResponse, Error, string> {\n const { sodax } = useSodaxContext();\n\n return useMutation<SupplyResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.supply(\n {\n token: spokeToken.address,\n amount: parseUnits(amount, spokeToken.decimals),\n action: 'supply',\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to supply tokens');\n }\n\n console.log('Supply transaction submitted:', response);\n return response;\n },\n });\n}\n","import type { SpokeProvider } from '@sodax/sdk';\nimport type { XToken } from '@sodax/types';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\nimport { parseUnits } from 'viem';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\ninterface WithdrawResponse {\n ok: true;\n value: [string, string];\n}\n\n/**\n * Hook for withdrawing supplied tokens from the Sodax money market.\n *\n * This hook provides functionality to withdraw previously supplied tokens from the money market protocol,\n * handling the entire withdrawal process including transaction creation, submission,\n * and cross-chain communication.\n *\n * @param {XToken} spokeToken - The token to withdraw from the spoke chain. Must be an XToken with valid address and chain information.\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for the withdraw transaction. Must be a valid SpokeProvider instance.\n *\n * @returns {UseMutationResult<WithdrawResponse, Error, string>} A mutation result object with the following properties:\n * - mutateAsync: Function to execute the withdraw transaction\n * - isPending: Boolean indicating if a transaction is in progress\n * @example\n * ```typescript\n * const { mutateAsync: withdraw, isPending, error } = useWithdraw(spokeToken);\n * await withdraw('100');\n * ```\n *\n * @throws {Error} When:\n * - spokeProvider is not available\n * - Transaction execution fails\n */\nexport function useWithdraw(\n spokeToken: XToken,\n spokeProvider: SpokeProvider | undefined,\n): UseMutationResult<WithdrawResponse, Error, string> {\n const { sodax } = useSodaxContext();\n\n return useMutation<WithdrawResponse, Error, string>({\n mutationFn: async (amount: string) => {\n if (!spokeProvider) {\n throw new Error('spokeProvider is not found');\n }\n\n const response = await sodax.moneyMarket.withdraw(\n {\n token: spokeToken.address,\n // vault token on hub chain decimals is 18\n amount: parseUnits(amount, 18),\n action: 'withdraw',\n },\n spokeProvider,\n );\n\n if (!response.ok) {\n throw new Error('Failed to withdraw tokens');\n }\n\n console.log('Withdraw transaction submitted:', response);\n return response;\n },\n });\n}\n","import { SpokeProvider, type UserReserveData } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\n/**\n * Hook for fetching user reserves data from the Sodax money market.\n *\n * This hook provides access to the current state of user reserves in the money market protocol.\n * The data is automatically fetched and cached using React Query.\n *\n * @example\n * ```typescript\n * const { data: userReservesData, isLoading, error } = useUserReservesData(spokeProvider, address);\n * ```\n *\n * @returns A React Query result object containing:\n * - data: The user reserves data when available\n * - isLoading: Loading state indicator\n * - error: Any error that occurred during data fetching\n */\nexport function useUserReservesData(\n spokeProvider: SpokeProvider | undefined,\n address: string | undefined,\n refetchInterval = 5000,\n): UseQueryResult<readonly [readonly UserReserveData[], number], Error> {\n const { sodax } = useSodaxContext();\n\n return useQuery({\n queryKey: ['userReserves', spokeProvider?.chainConfig.chain.id, address],\n queryFn: async () => {\n if (!spokeProvider) {\n throw new Error('Spoke provider or address is not defined');\n }\n\n return await sodax.moneyMarket.data.getUserReservesData(spokeProvider);\n },\n enabled: !!spokeProvider && !!address,\n refetchInterval,\n });\n}\n","import { useQuery } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n/**\n * Hook for fetching reserves data from the Sodax money market.\n *\n * This hook provides access to the current state of all reserves in the money market protocol,\n * including liquidity, interest rates, and other key metrics. The data is automatically\n * fetched and cached using React Query.\n *\n * @example\n * ```typescript\n * const { data: reservesData, isLoading, error } = useReservesData();\n * ```\n *\n * @returns A React Query result object containing:\n * - data: The reserves data when available\n * - isLoading: Loading state indicator\n * - error: Any error that occurred during data fetching\n */\n\nexport function useReservesData() {\n const { sodax } = useSodaxContext();\n\n return useQuery({\n queryKey: ['reservesData'],\n queryFn: async () => {\n return await sodax.moneyMarket.data.getReservesData();\n },\n });\n}\n","import { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport type { XToken } from '@sodax/types';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { parseUnits } from 'viem';\nimport type { MoneyMarketAction, SpokeProvider } from '@sodax/sdk';\n\n/**\n * Hook for checking token allowance for money market operations.\n *\n * This hook verifies if the user has approved enough tokens for a specific money market action\n * (borrow/repay). It automatically queries and tracks the allowance status.\n *\n * @param {XToken} token - The token to check allowance for. Must be an XToken with valid address and chain information.\n * @param {string} amount - The amount to check allowance for, as a decimal string\n * @param {MoneyMarketAction} action - The money market action to check allowance for ('borrow' or 'repay')\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for allowance checks\n *\n * @returns {UseQueryResult<boolean, Error>} A React Query result containing:\n * - data: Boolean indicating if allowance is sufficient\n * - isLoading: Loading state indicator\n * - error: Any error that occurred during the check\n *\n * @example\n * ```typescript\n * const { data: hasAllowed, isLoading } = useMMAllowance(token, \"100\", \"repay\", provider);\n * ```\n */\nexport function useMMAllowance(\n token: XToken,\n amount: string,\n action: MoneyMarketAction,\n spokeProvider: SpokeProvider | undefined,\n): UseQueryResult<boolean, Error> {\n const { sodax } = useSodaxContext();\n\n return useQuery({\n queryKey: ['allowance', token.address, amount, action],\n queryFn: async () => {\n if (!spokeProvider) throw new Error('Spoke provider is required');\n const allowance = await sodax.moneyMarket.isAllowanceValid(\n {\n token: token.address,\n amount: parseUnits(amount, token.decimals),\n action,\n },\n spokeProvider,\n );\n if (allowance.ok) {\n return allowance.value;\n }\n return false;\n },\n enabled: !!spokeProvider,\n });\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type { XToken } from '@sodax/types';\nimport { parseUnits } from 'viem';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type { MoneyMarketAction, SpokeProvider } from '@sodax/sdk';\n\ninterface UseApproveReturn {\n approve: ({ amount, action }: { amount: string; action: MoneyMarketAction }) => Promise<boolean>;\n isLoading: boolean;\n error: Error | null;\n resetError: () => void;\n}\n\n/**\n * Hook for approving token spending for money market actions\n * @param token The token to approve spending for\n * @param spokeProvider The spoke provider instance for the chain\n * @returns Object containing approve function, loading state, error state and reset function\n * @example\n * ```tsx\n * const { approve, isLoading, error } = useMMApprove(token, spokeProvider);\n *\n * // Approve tokens for supply action\n * await approve({ amount: \"100\", action: \"supply\" });\n * ```\n */\n\nexport function useMMApprove(token: XToken, spokeProvider: SpokeProvider | undefined): UseApproveReturn {\n const { sodax } = useSodaxContext();\n const queryClient = useQueryClient();\n\n const {\n mutateAsync: approve,\n isPending,\n error,\n reset: resetError,\n } = useMutation({\n mutationFn: async ({ amount, action }: { amount: string; action: MoneyMarketAction }) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n const allowance = await sodax.moneyMarket.approve(\n {\n token: token.address,\n amount: parseUnits(amount, token.decimals),\n action,\n },\n spokeProvider,\n );\n if (!allowance.ok) {\n throw new Error('Failed to approve tokens');\n }\n return allowance.ok;\n },\n onSuccess: () => {\n // Invalidate allowance query to refetch the new allowance\n queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });\n },\n });\n\n return {\n approve,\n isLoading: isPending,\n error: error,\n resetError,\n };\n}\n","import type { SolverErrorResponse, SolverIntentQuoteRequest, SolverIntentQuoteResponse, Result } from '@sodax/sdk';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\n\n/**\n * Hook for fetching a quote for an intent-based swap.\n *\n * This hook provides real-time quote data for an intent-based swap.\n *\n * @param {SolverIntentQuoteRequest | undefined} payload - The intent quote request parameters. If undefined, the query will be disabled.\n *\n * @returns {UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined>} A query result object containing:\n * - data: The quote result from the solver\n * - isLoading: Boolean indicating if the quote is being fetched\n * - error: Error object if the quote request failed\n * - refetch: Function to manually trigger a quote refresh\n *\n * @example\n * ```typescript\n * const { data: quote, isLoading } = useQuote({\n * token_src: '0x...',\n * token_src_blockchain_id: '1',\n * token_dst: '0x...',\n * token_dst_blockchain_id: '2',\n * amount: '1000000000000000000',\n * quote_type: 'exact_input',\n * });\n *\n * if (isLoading) return <div>Loading quote...</div>;\n * if (quote) {\n * console.log('Quote received:', quote);\n * }\n * ```\n *\n * @remarks\n * - The quote is automatically refreshed every 3 seconds\n * - The query is disabled when payload is undefined\n * - Uses React Query for efficient caching and state management\n */\nexport const useQuote = (\n payload: SolverIntentQuoteRequest | undefined,\n): UseQueryResult<Result<SolverIntentQuoteResponse, SolverErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [payload],\n queryFn: async () => {\n if (!payload) {\n return undefined;\n }\n return sodax.solver.getQuote(payload);\n },\n enabled: !!payload,\n refetchInterval: 3000,\n });\n};\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type {\n CreateIntentParams,\n SolverExecutionResponse,\n Result,\n IntentErrorCode,\n Intent,\n IntentError,\n SpokeProvider,\n IntentDeliveryInfo,\n} from '@sodax/sdk';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\ntype CreateIntentResult = Result<[SolverExecutionResponse, Intent, IntentDeliveryInfo], IntentError<IntentErrorCode>>;\n\n/**\n * Hook for creating and submitting an swap intent order for cross-chain swaps.\n * Uses React Query's useMutation for better state management and caching.\n *\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for the swap\n * @returns {UseMutationResult} Mutation result object containing mutation function and state\n *\n * @example\n * ```typescript\n * const { mutateAsync: swap, isPending } = useSwap(spokeProvider);\n *\n * const handleSwap = async () => {\n * const result = await swap({\n * token_src: '0x...',\n * token_src_blockchain_id: 'arbitrum',\n * token_dst: '0x...',\n * token_dst_blockchain_id: 'polygon',\n * amount: '1000000000000000000',\n * min_output_amount: '900000000000000000'\n * });\n * };\n * ```\n */\nexport function useSwap(\n spokeProvider: SpokeProvider | undefined,\n): UseMutationResult<CreateIntentResult, Error, CreateIntentParams> {\n const { sodax } = useSodaxContext();\n\n return useMutation<CreateIntentResult, Error, CreateIntentParams>({\n mutationFn: async (params: CreateIntentParams) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n return sodax.solver.swap({\n intentParams: params,\n spokeProvider,\n });\n },\n });\n}\n","import type { Hex, SolverErrorResponse, SolverIntentStatusResponse, Result } from '@sodax/sdk';\nimport { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\n\n/**\n * Hook for monitoring the status of an intent-based swap.\n *\n * This hook provides real-time status updates for an intent-based swap transaction.\n *\n * @param {Hex} intent_tx_hash - The transaction hash of the intent order on the hub chain\n *\n * @returns {UseQueryResult<Result<SolverIntentStatusResponse, SolverErrorResponse> | undefined>} A query result object containing:\n * - data: The status result from the solver\n * - isLoading: Boolean indicating if the status is being fetched\n * - error: Error object if the status request failed\n * - refetch: Function to manually trigger a status refresh\n *\n * @example\n * ```typescript\n * const { data: status, isLoading } = useStatus('0x...');\n *\n * if (isLoading) return <div>Loading status...</div>;\n * if (status?.ok) {\n * console.log('Status:', status.value);\n * }\n * ```\n *\n * @remarks\n * - The status is automatically refreshed every 3 seconds\n * - Uses React Query for efficient caching and state management\n */\n\nexport const useStatus = (\n intent_tx_hash: Hex,\n): UseQueryResult<Result<SolverIntentStatusResponse, SolverErrorResponse> | undefined> => {\n const { sodax } = useSodaxContext();\n return useQuery({\n queryKey: [intent_tx_hash],\n queryFn: async () => {\n return sodax.solver.getStatus({ intent_tx_hash });\n },\n refetchInterval: 3000, // 3s\n });\n};\n","import { useQuery, type UseQueryResult } from '@tanstack/react-query';\nimport { useSodaxContext } from '../shared/useSodaxContext';\nimport type { CreateIntentParams, SpokeProvider } from '@sodax/sdk';\n\n/**\n * Hook for checking token allowance for money market operations.\n *\n * This hook verifies if the user has approved enough tokens for a specific money market action\n * (borrow/repay). It automatically queries and tracks the allowance status.\n *\n * @param {CreateIntentParams} params - The parameters for the intent to check allowance for.\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for allowance checks\n *\n * @returns {UseQueryResult<boolean, Error>} A React Query result containing:\n * - data: Boolean indicating if allowance is sufficient\n * - isLoading: Loading state indicator\n * - error: Any error that occurred during the check\n *\n * @example\n * ```typescript\n * const { data: hasAllowed, isLoading } = useMMAllowance(params, spokeProvider);\n * ```\n */\nexport function useSwapAllowance(\n params: CreateIntentParams | undefined,\n spokeProvider: SpokeProvider | undefined,\n): UseQueryResult<boolean, Error> {\n const { sodax } = useSodaxContext();\n\n return useQuery({\n queryKey: ['allowance', params],\n queryFn: async () => {\n if (!spokeProvider || !params) {\n return false;\n }\n const allowance = await sodax.solver.isAllowanceValid({\n intentParams: params,\n spokeProvider,\n });\n if (allowance.ok) {\n return allowance.value;\n }\n return false;\n },\n enabled: !!spokeProvider && !!params,\n });\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport { useMutation, useQueryClient } from '@tanstack/react-query';\nimport type { CreateIntentParams, SpokeProvider } from '@sodax/sdk';\n\ninterface UseApproveReturn {\n approve: ({ params }: { params: CreateIntentParams }) => Promise<boolean>;\n isLoading: boolean;\n error: Error | null;\n resetError: () => void;\n}\n\n/**\n * Hook for approving token spending for money market actions\n * @param token The token to approve spending for\n * @param spokeProvider The spoke provider instance for the chain\n * @returns Object containing approve function, loading state, error state and reset function\n * @example\n * ```tsx\n * const { approve, isLoading, error } = useApprove(token, spokeProvider);\n *\n * // Approve tokens for supply action\n * await approve({ amount: \"100\", action: \"supply\" });\n * ```\n */\n\nexport function useSwapApprove(\n params: CreateIntentParams | undefined,\n spokeProvider: SpokeProvider | undefined,\n): UseApproveReturn {\n const { sodax } = useSodaxContext();\n const queryClient = useQueryClient();\n\n const {\n mutateAsync: approve,\n isPending,\n error,\n reset: resetError,\n } = useMutation({\n mutationFn: async ({ params }: { params: CreateIntentParams | undefined }) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n if (!params) {\n throw new Error('Swap Params not found');\n }\n\n const allowance = await sodax.solver.approve({\n intentParams: params,\n spokeProvider,\n });\n if (!allowance.ok) {\n throw new Error('Failed to approve input token');\n }\n return allowance.ok;\n },\n onSuccess: () => {\n // Invalidate allowance query to refetch the new allowance\n queryClient.invalidateQueries({ queryKey: ['allowance', params?.inputToken] });\n },\n });\n\n return {\n approve,\n isLoading: isPending,\n error: error,\n resetError,\n };\n}\n","import { useSodaxContext } from '../shared/useSodaxContext';\nimport type { Intent, Result, SpokeProvider, TxReturnType } from '@sodax/sdk';\nimport { useMutation, type UseMutationResult } from '@tanstack/react-query';\n\ntype CancelIntentParams = {\n intent: Intent;\n raw?: boolean;\n};\n\ntype CancelIntentResult = Result<TxReturnType<SpokeProvider, boolean>>;\n\n/**\n * Hook for canceling a swap intent order.\n * Uses React Query's useMutation for better state management and caching.\n *\n * @param {SpokeProvider} spokeProvider - The spoke provider to use for canceling the intent\n * @returns {UseMutationResult} Mutation result object containing mutation function and state\n *\n * @example\n * ```typescript\n * const { mutateAsync: cancelSwap, isPending } = useCancelSwap(spokeProvider);\n *\n * const handleCancelSwap = async () => {\n * const result = await cancelSwap({\n * intent: intentObject,\n * raw: false // optional, defaults to false\n * });\n * };\n * ```\n */\nexport function useCancelSwap(\n spokeProvider: SpokeProvider | undefined,\n): UseMutationResult<CancelIntentResult, Error, CancelIntentParams> {\n const { sodax } = useSodaxContext();\n\n return useMutation<CancelIntentResult, Error, CancelIntentParams>({\n mutationFn: async ({ intent, raw = false }: CancelIntentParams) => {\n if (!spokeProvider) {\n throw new Error('Spoke provider not found');\n }\n return sodax.solver.cancelIntent(intent, spokeProvider, raw);\n },\n });\n}\n","import type { ReactNode, ReactElement } from 'react';\nimport { EvmHubProvider, getHubChainConfig, Sodax, type SodaxConfig } from '@sodax/sdk';\nimport { SodaxContext } from '@/contexts';\nimport React, { useMemo } from 'react';\nimport type { RpcConfig } from '@/types';\n\ninterface SodaxProviderProps {\n children: ReactNode;\n testnet?: boolean;\n config?: SodaxConfig;\n rpcConfig: RpcConfig;\n}\n\nexport const SodaxProvider = ({ children, testnet = false, config, rpcConfig }: SodaxProviderProps): ReactElement => {\n const sodax = new Sodax(config);\n\n const hubChainId = config?.hubProviderConfig?.chainConfig.chain.id;\n const hubRpcUrl = config?.hubProviderConfig?.hubRpcUrl;\n\n const hubProvider = useMemo(() => {\n if (hubChainId && hubRpcUrl) {\n const hubChainCfg = getHubChainConfig(hubChainId);\n\n return new EvmHubProvider({\n hubRpcUrl: hubRpcUrl,\n chainConfig: hubChainCfg,\n });\n }\n return undefined;\n }, [hubChainId, hubRpcUrl]);\n\n return <SodaxContext.Provider value={{ sodax, testnet, hubProvider, rpcConfig }}>{children}</SodaxContext.Provider>;\n};\n","import type { ChainId } from '@sodax/types';\n\nimport { hubAssets } from '@sodax/sdk';\n\nexport const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {\n const tokens = hubAssets[spokeChainId];\n const address = Object.keys(tokens).find(\n tokenAddress => tokens[tokenAddress].vault.toLowerCase() === vault.toLowerCase(),\n );\n\n return address;\n};\n"]}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { ReactNode, ReactElement } from 'react';
|
|
2
2
|
import { type SodaxConfig } from '@sodax/sdk';
|
|
3
|
+
import type { RpcConfig } from '@/types';
|
|
3
4
|
interface SodaxProviderProps {
|
|
4
5
|
children: ReactNode;
|
|
5
6
|
testnet?: boolean;
|
|
6
|
-
config
|
|
7
|
+
config?: SodaxConfig;
|
|
8
|
+
rpcConfig: RpcConfig;
|
|
7
9
|
}
|
|
8
|
-
export declare const SodaxProvider: ({ children, testnet, config }: SodaxProviderProps) => ReactElement;
|
|
10
|
+
export declare const SodaxProvider: ({ children, testnet, config, rpcConfig }: SodaxProviderProps) => ReactElement;
|
|
9
11
|
export {};
|
|
10
12
|
//# sourceMappingURL=SodaxProvider.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SodaxProvider.d.ts","sourceRoot":"","sources":["../../src/providers/SodaxProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,
|
|
1
|
+
{"version":3,"file":"SodaxProvider.d.ts","sourceRoot":"","sources":["../../src/providers/SodaxProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AACrD,OAAO,EAA4C,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAGxF,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAEzC,UAAU,kBAAkB;IAC1B,QAAQ,EAAE,SAAS,CAAC;IACpB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,WAAW,CAAC;IACrB,SAAS,EAAE,SAAS,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,6CAAsD,kBAAkB,KAAG,YAmBpG,CAAC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { StellarRpcConfig } from '@sodax/sdk';
|
|
2
|
+
export type RpcConfig = {
|
|
3
|
+
sonic?: string;
|
|
4
|
+
'0xa86a.avax'?: string;
|
|
5
|
+
'0xa4b1.arbitrum'?: string;
|
|
6
|
+
'0x2105.base'?: string;
|
|
7
|
+
'0x38.bsc'?: string;
|
|
8
|
+
'0xa.optimism'?: string;
|
|
9
|
+
'0x89.polygon'?: string;
|
|
10
|
+
nibiru?: string;
|
|
11
|
+
'injective-1'?: string;
|
|
12
|
+
sui?: string;
|
|
13
|
+
solana?: string;
|
|
14
|
+
'0x1.icon'?: string;
|
|
15
|
+
stellar?: StellarRpcConfig;
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnD,MAAM,MAAM,SAAS,GAAG;IAEtB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,CAAC;IAGhB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,OAAO,CAAC,EAAE,gBAAgB,CAAC;CAC5B,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sodax/dapp-kit",
|
|
3
3
|
"license": "MIT",
|
|
4
|
-
"version": "0.0.1-rc.
|
|
4
|
+
"version": "0.0.1-rc.21",
|
|
5
5
|
"description": "dapp-kit of New World",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -16,9 +16,8 @@
|
|
|
16
16
|
},
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"viem": "^2.29.2",
|
|
19
|
-
"@sodax/sdk": "0.0.1-rc.
|
|
20
|
-
"@sodax/types": "0.0.1-rc.
|
|
21
|
-
"@sodax/wallet-sdk": "0.0.1-rc.1"
|
|
19
|
+
"@sodax/sdk": "0.0.1-rc.31",
|
|
20
|
+
"@sodax/types": "0.0.1-rc.15"
|
|
22
21
|
},
|
|
23
22
|
"devDependencies": {
|
|
24
23
|
"@types/react": "^19.0.8",
|
|
@@ -27,8 +26,8 @@
|
|
|
27
26
|
"typescript": "5.5.4"
|
|
28
27
|
},
|
|
29
28
|
"peerDependencies": {
|
|
30
|
-
"@tanstack/react-query": "
|
|
31
|
-
"react": "
|
|
29
|
+
"@tanstack/react-query": "5.x",
|
|
30
|
+
"react": ">=18"
|
|
32
31
|
},
|
|
33
32
|
"engines": {
|
|
34
33
|
"node": ">=18.0.0"
|
package/src/contexts/index.ts
CHANGED
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { createContext } from 'react';
|
|
2
|
-
import type { Sodax } from '@sodax/sdk';
|
|
2
|
+
import type { EvmHubProvider, Sodax } from '@sodax/sdk';
|
|
3
|
+
import type { RpcConfig } from '@/types';
|
|
3
4
|
|
|
4
5
|
export interface SodaxContextType {
|
|
5
6
|
sodax: Sodax;
|
|
6
7
|
testnet: boolean;
|
|
8
|
+
hubProvider: EvmHubProvider | undefined;
|
|
9
|
+
rpcConfig: RpcConfig;
|
|
7
10
|
}
|
|
8
11
|
|
|
9
12
|
export const SodaxContext = createContext<SodaxContextType | null>(null);
|
package/src/core/index.ts
CHANGED
|
@@ -1,40 +1,12 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ChainId } from '@sodax/types';
|
|
2
2
|
|
|
3
3
|
import { hubAssets } from '@sodax/sdk';
|
|
4
4
|
|
|
5
|
-
export const allXTokens: XToken[] = [];
|
|
6
|
-
|
|
7
|
-
Object.keys(hubAssets).forEach(xChainId => {
|
|
8
|
-
const tokens = hubAssets[xChainId];
|
|
9
|
-
|
|
10
|
-
Object.keys(tokens).forEach(tokenAddress => {
|
|
11
|
-
const token = tokens[tokenAddress];
|
|
12
|
-
allXTokens.push({
|
|
13
|
-
xChainId: xChainId as ChainId,
|
|
14
|
-
symbol: token.symbol,
|
|
15
|
-
name: token.name,
|
|
16
|
-
decimals: token.decimal,
|
|
17
|
-
address: tokenAddress,
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
allXTokens.push({
|
|
21
|
-
xChainId: 'sonic',
|
|
22
|
-
symbol: token.symbol,
|
|
23
|
-
name: token.name,
|
|
24
|
-
decimals: token.decimal,
|
|
25
|
-
address: token.vault,
|
|
26
|
-
});
|
|
27
|
-
});
|
|
28
|
-
});
|
|
29
|
-
|
|
30
5
|
export const getSpokeTokenAddressByVault = (spokeChainId: ChainId, vault: string) => {
|
|
31
6
|
const tokens = hubAssets[spokeChainId];
|
|
7
|
+
const address = Object.keys(tokens).find(
|
|
8
|
+
tokenAddress => tokens[tokenAddress].vault.toLowerCase() === vault.toLowerCase(),
|
|
9
|
+
);
|
|
32
10
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
if (!token) {
|
|
36
|
-
throw new Error('Token not found');
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
return token;
|
|
11
|
+
return address;
|
|
40
12
|
};
|
package/src/hooks/mm/index.ts
CHANGED
|
@@ -3,4 +3,6 @@ export * from './useRepay';
|
|
|
3
3
|
export * from './useSupply';
|
|
4
4
|
export * from './useWithdraw';
|
|
5
5
|
export * from './useUserReservesData';
|
|
6
|
-
export * from './
|
|
6
|
+
export * from './useReservesData';
|
|
7
|
+
export * from './useMMAllowance';
|
|
8
|
+
export * from './useMMApprove';
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { XToken } from '@sodax/types';
|
|
2
2
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
3
3
|
import { parseUnits } from 'viem';
|
|
4
|
-
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
5
4
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
6
|
-
import type {
|
|
5
|
+
import type { SpokeProvider } from '@sodax/sdk';
|
|
7
6
|
interface BorrowResponse {
|
|
8
7
|
ok: true;
|
|
9
|
-
value: [
|
|
8
|
+
value: [string, string];
|
|
10
9
|
}
|
|
11
10
|
|
|
12
11
|
/**
|
|
@@ -16,9 +15,17 @@ interface BorrowResponse {
|
|
|
16
15
|
* handling the entire borrow process including transaction creation, submission,
|
|
17
16
|
* and cross-chain communication.
|
|
18
17
|
*
|
|
18
|
+
* @param {XToken} spokeToken - The token to borrow from the spoke chain. Must be an XToken with valid address and chain information.
|
|
19
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the borrow transaction. Must be a valid SpokeProvider instance.
|
|
20
|
+
*
|
|
21
|
+
* @returns {UseMutationResult<BorrowResponse, Error, string>} A mutation result object with the following properties:
|
|
22
|
+
* - mutateAsync: Function to execute the borrow transaction
|
|
23
|
+
* - isPending: Boolean indicating if a transaction is in progress
|
|
24
|
+
* - error: Error object if the last transaction failed, null otherwise
|
|
25
|
+
*
|
|
19
26
|
* @example
|
|
20
27
|
* ```typescript
|
|
21
|
-
* const { mutateAsync: borrow, isPending, error } = useBorrow(
|
|
28
|
+
* const { mutateAsync: borrow, isPending, error } = useBorrow(spokeToken);
|
|
22
29
|
* await borrow('100');
|
|
23
30
|
* ```
|
|
24
31
|
*
|
|
@@ -26,9 +33,11 @@ interface BorrowResponse {
|
|
|
26
33
|
* - spokeProvider is not available
|
|
27
34
|
* - Transaction execution fails
|
|
28
35
|
*/
|
|
29
|
-
export function useBorrow(
|
|
36
|
+
export function useBorrow(
|
|
37
|
+
spokeToken: XToken,
|
|
38
|
+
spokeProvider: SpokeProvider | undefined,
|
|
39
|
+
): UseMutationResult<BorrowResponse, Error, string> {
|
|
30
40
|
const { sodax } = useSodaxContext();
|
|
31
|
-
const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);
|
|
32
41
|
|
|
33
42
|
return useMutation<BorrowResponse, Error, string>({
|
|
34
43
|
mutationFn: async (amount: string) => {
|
|
@@ -36,10 +45,11 @@ export function useBorrow(hubToken: XToken, spokeChainId: ChainId): UseMutationR
|
|
|
36
45
|
throw new Error('spokeProvider is not found');
|
|
37
46
|
}
|
|
38
47
|
|
|
39
|
-
const response = await sodax.moneyMarket.
|
|
48
|
+
const response = await sodax.moneyMarket.borrow(
|
|
40
49
|
{
|
|
41
|
-
token:
|
|
42
|
-
amount: parseUnits(amount,
|
|
50
|
+
token: spokeToken.address,
|
|
51
|
+
amount: parseUnits(amount, 18),
|
|
52
|
+
action: 'borrow',
|
|
43
53
|
},
|
|
44
54
|
spokeProvider,
|
|
45
55
|
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { XToken } from '@sodax/types';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
4
|
+
import { parseUnits } from 'viem';
|
|
5
|
+
import type { MoneyMarketAction, SpokeProvider } from '@sodax/sdk';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hook for checking token allowance for money market operations.
|
|
9
|
+
*
|
|
10
|
+
* This hook verifies if the user has approved enough tokens for a specific money market action
|
|
11
|
+
* (borrow/repay). It automatically queries and tracks the allowance status.
|
|
12
|
+
*
|
|
13
|
+
* @param {XToken} token - The token to check allowance for. Must be an XToken with valid address and chain information.
|
|
14
|
+
* @param {string} amount - The amount to check allowance for, as a decimal string
|
|
15
|
+
* @param {MoneyMarketAction} action - The money market action to check allowance for ('borrow' or 'repay')
|
|
16
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for allowance checks
|
|
17
|
+
*
|
|
18
|
+
* @returns {UseQueryResult<boolean, Error>} A React Query result containing:
|
|
19
|
+
* - data: Boolean indicating if allowance is sufficient
|
|
20
|
+
* - isLoading: Loading state indicator
|
|
21
|
+
* - error: Any error that occurred during the check
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* ```typescript
|
|
25
|
+
* const { data: hasAllowed, isLoading } = useMMAllowance(token, "100", "repay", provider);
|
|
26
|
+
* ```
|
|
27
|
+
*/
|
|
28
|
+
export function useMMAllowance(
|
|
29
|
+
token: XToken,
|
|
30
|
+
amount: string,
|
|
31
|
+
action: MoneyMarketAction,
|
|
32
|
+
spokeProvider: SpokeProvider | undefined,
|
|
33
|
+
): UseQueryResult<boolean, Error> {
|
|
34
|
+
const { sodax } = useSodaxContext();
|
|
35
|
+
|
|
36
|
+
return useQuery({
|
|
37
|
+
queryKey: ['allowance', token.address, amount, action],
|
|
38
|
+
queryFn: async () => {
|
|
39
|
+
if (!spokeProvider) throw new Error('Spoke provider is required');
|
|
40
|
+
const allowance = await sodax.moneyMarket.isAllowanceValid(
|
|
41
|
+
{
|
|
42
|
+
token: token.address,
|
|
43
|
+
amount: parseUnits(amount, token.decimals),
|
|
44
|
+
action,
|
|
45
|
+
},
|
|
46
|
+
spokeProvider,
|
|
47
|
+
);
|
|
48
|
+
if (allowance.ok) {
|
|
49
|
+
return allowance.value;
|
|
50
|
+
}
|
|
51
|
+
return false;
|
|
52
|
+
},
|
|
53
|
+
enabled: !!spokeProvider,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
2
|
+
import type { XToken } from '@sodax/types';
|
|
3
|
+
import { parseUnits } from 'viem';
|
|
4
|
+
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
|
5
|
+
import type { MoneyMarketAction, SpokeProvider } from '@sodax/sdk';
|
|
6
|
+
|
|
7
|
+
interface UseApproveReturn {
|
|
8
|
+
approve: ({ amount, action }: { amount: string; action: MoneyMarketAction }) => Promise<boolean>;
|
|
9
|
+
isLoading: boolean;
|
|
10
|
+
error: Error | null;
|
|
11
|
+
resetError: () => void;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Hook for approving token spending for money market actions
|
|
16
|
+
* @param token The token to approve spending for
|
|
17
|
+
* @param spokeProvider The spoke provider instance for the chain
|
|
18
|
+
* @returns Object containing approve function, loading state, error state and reset function
|
|
19
|
+
* @example
|
|
20
|
+
* ```tsx
|
|
21
|
+
* const { approve, isLoading, error } = useMMApprove(token, spokeProvider);
|
|
22
|
+
*
|
|
23
|
+
* // Approve tokens for supply action
|
|
24
|
+
* await approve({ amount: "100", action: "supply" });
|
|
25
|
+
* ```
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
export function useMMApprove(token: XToken, spokeProvider: SpokeProvider | undefined): UseApproveReturn {
|
|
29
|
+
const { sodax } = useSodaxContext();
|
|
30
|
+
const queryClient = useQueryClient();
|
|
31
|
+
|
|
32
|
+
const {
|
|
33
|
+
mutateAsync: approve,
|
|
34
|
+
isPending,
|
|
35
|
+
error,
|
|
36
|
+
reset: resetError,
|
|
37
|
+
} = useMutation({
|
|
38
|
+
mutationFn: async ({ amount, action }: { amount: string; action: MoneyMarketAction }) => {
|
|
39
|
+
if (!spokeProvider) {
|
|
40
|
+
throw new Error('Spoke provider not found');
|
|
41
|
+
}
|
|
42
|
+
const allowance = await sodax.moneyMarket.approve(
|
|
43
|
+
{
|
|
44
|
+
token: token.address,
|
|
45
|
+
amount: parseUnits(amount, token.decimals),
|
|
46
|
+
action,
|
|
47
|
+
},
|
|
48
|
+
spokeProvider,
|
|
49
|
+
);
|
|
50
|
+
if (!allowance.ok) {
|
|
51
|
+
throw new Error('Failed to approve tokens');
|
|
52
|
+
}
|
|
53
|
+
return allowance.ok;
|
|
54
|
+
},
|
|
55
|
+
onSuccess: () => {
|
|
56
|
+
// Invalidate allowance query to refetch the new allowance
|
|
57
|
+
queryClient.invalidateQueries({ queryKey: ['allowance', token.address] });
|
|
58
|
+
},
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
approve,
|
|
63
|
+
isLoading: isPending,
|
|
64
|
+
error: error,
|
|
65
|
+
resetError,
|
|
66
|
+
};
|
|
67
|
+
}
|
package/src/hooks/mm/useRepay.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type {
|
|
1
|
+
import type { SpokeProvider } from '@sodax/sdk';
|
|
2
|
+
import type { XToken } from '@sodax/types';
|
|
3
3
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query';
|
|
4
4
|
import { parseUnits } from 'viem';
|
|
5
|
-
import { useSpokeProvider } from '../provider/useSpokeProvider';
|
|
6
5
|
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
7
6
|
|
|
8
7
|
interface RepayResponse {
|
|
9
8
|
ok: true;
|
|
10
|
-
value: [
|
|
9
|
+
value: [string, string];
|
|
11
10
|
}
|
|
12
11
|
|
|
13
12
|
/**
|
|
@@ -17,9 +16,17 @@ interface RepayResponse {
|
|
|
17
16
|
* handling the entire repayment process including transaction creation, submission,
|
|
18
17
|
* and cross-chain communication.
|
|
19
18
|
*
|
|
19
|
+
* @param {XToken} spokeToken - The token to repay on the spoke chain. Must be an XToken with valid address and chain information.
|
|
20
|
+
* @param {SpokeProvider} spokeProvider - The spoke provider to use for the repay transaction. Must be a valid SpokeProvider instance.
|
|
21
|
+
*
|
|
22
|
+
* @returns {UseMutationResult<RepayResponse, Error, string>} A mutation result object with the following properties:
|
|
23
|
+
* - mutateAsync: Function to execute the repay transaction
|
|
24
|
+
* - isPending: Boolean indicating if a transaction is in progress
|
|
25
|
+
* - error: Error object if the last transaction failed, null otherwise
|
|
26
|
+
*
|
|
20
27
|
* @example
|
|
21
28
|
* ```typescript
|
|
22
|
-
* const { mutateAsync: repay, isPending, error } = useRepay(
|
|
29
|
+
* const { mutateAsync: repay, isPending, error } = useRepay(spokeToken);
|
|
23
30
|
* await repay('100');
|
|
24
31
|
* ```
|
|
25
32
|
*
|
|
@@ -27,9 +34,11 @@ interface RepayResponse {
|
|
|
27
34
|
* - spokeProvider is not available
|
|
28
35
|
* - Transaction execution fails
|
|
29
36
|
*/
|
|
30
|
-
export function useRepay(
|
|
37
|
+
export function useRepay(
|
|
38
|
+
spokeToken: XToken,
|
|
39
|
+
spokeProvider: SpokeProvider | undefined,
|
|
40
|
+
): UseMutationResult<RepayResponse, Error, string> {
|
|
31
41
|
const { sodax } = useSodaxContext();
|
|
32
|
-
const spokeProvider = useSpokeProvider(spokeChainId as SpokeChainId);
|
|
33
42
|
|
|
34
43
|
return useMutation<RepayResponse, Error, string>({
|
|
35
44
|
mutationFn: async (amount: string) => {
|
|
@@ -37,10 +46,11 @@ export function useRepay(hubToken: XToken, spokeChainId: ChainId): UseMutationRe
|
|
|
37
46
|
throw new Error('spokeProvider is not found');
|
|
38
47
|
}
|
|
39
48
|
|
|
40
|
-
const response = await sodax.moneyMarket.
|
|
49
|
+
const response = await sodax.moneyMarket.repay(
|
|
41
50
|
{
|
|
42
|
-
token:
|
|
43
|
-
amount: parseUnits(amount,
|
|
51
|
+
token: spokeToken.address,
|
|
52
|
+
amount: parseUnits(amount, spokeToken.decimals),
|
|
53
|
+
action: 'repay',
|
|
44
54
|
},
|
|
45
55
|
spokeProvider,
|
|
46
56
|
);
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { useQuery } from '@tanstack/react-query';
|
|
2
|
+
import { useSodaxContext } from '../shared/useSodaxContext';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for fetching reserves data from the Sodax money market.
|
|
5
|
+
*
|
|
6
|
+
* This hook provides access to the current state of all reserves in the money market protocol,
|
|
7
|
+
* including liquidity, interest rates, and other key metrics. The data is automatically
|
|
8
|
+
* fetched and cached using React Query.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const { data: reservesData, isLoading, error } = useReservesData();
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* @returns A React Query result object containing:
|
|
16
|
+
* - data: The reserves data when available
|
|
17
|
+
* - isLoading: Loading state indicator
|
|
18
|
+
* - error: Any error that occurred during data fetching
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export function useReservesData() {
|
|
22
|
+
const { sodax } = useSodaxContext();
|
|
23
|
+
|
|
24
|
+
return useQuery({
|
|
25
|
+
queryKey: ['reservesData'],
|
|
26
|
+
queryFn: async () => {
|
|
27
|
+
return await sodax.moneyMarket.data.getReservesData();
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
}
|