@sodax/dapp-kit 1.5.6-beta → 2.0.0-rc.1
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 +300 -422
- package/ai-exported/AGENTS.md +134 -0
- package/ai-exported/integration/README.md +49 -0
- package/ai-exported/integration/ai-rules.md +79 -0
- package/ai-exported/integration/architecture.md +274 -0
- package/ai-exported/integration/features/README.md +29 -0
- package/ai-exported/integration/features/auxiliary-services.md +169 -0
- package/ai-exported/integration/features/bitcoin.md +87 -0
- package/ai-exported/integration/features/bridge.md +91 -0
- package/ai-exported/integration/features/dex.md +152 -0
- package/ai-exported/integration/features/migration.md +118 -0
- package/ai-exported/integration/features/money-market.md +116 -0
- package/ai-exported/integration/features/staking.md +123 -0
- package/ai-exported/integration/features/swap.md +101 -0
- package/ai-exported/integration/quickstart.md +187 -0
- package/ai-exported/integration/recipes/README.md +136 -0
- package/ai-exported/integration/recipes/backend-queries.md +157 -0
- package/ai-exported/integration/recipes/bitcoin.md +193 -0
- package/ai-exported/integration/recipes/bridge.md +174 -0
- package/ai-exported/integration/recipes/dex.md +204 -0
- package/ai-exported/integration/recipes/invalidations.md +115 -0
- package/ai-exported/integration/recipes/migration.md +212 -0
- package/ai-exported/integration/recipes/money-market.md +206 -0
- package/ai-exported/integration/recipes/mutation-error-handling.md +118 -0
- package/ai-exported/integration/recipes/observability.md +93 -0
- package/ai-exported/integration/recipes/setup.md +144 -0
- package/ai-exported/integration/recipes/staking.md +202 -0
- package/ai-exported/integration/recipes/swap.md +272 -0
- package/ai-exported/integration/recipes/wallet-connectivity.md +101 -0
- package/ai-exported/integration/reference/README.md +12 -0
- package/ai-exported/integration/reference/glossary.md +188 -0
- package/ai-exported/integration/reference/hooks-index.md +194 -0
- package/ai-exported/integration/reference/public-api.md +110 -0
- package/ai-exported/integration/reference/querykey-conventions.md +179 -0
- package/ai-exported/migration/README.md +60 -0
- package/ai-exported/migration/ai-rules.md +81 -0
- package/ai-exported/migration/breaking-changes/hook-signatures.md +233 -0
- package/ai-exported/migration/breaking-changes/querykey-conventions.md +108 -0
- package/ai-exported/migration/breaking-changes/result-handling.md +211 -0
- package/ai-exported/migration/breaking-changes/sdk-leakage.md +165 -0
- package/ai-exported/migration/checklist.md +89 -0
- package/ai-exported/migration/features/README.md +34 -0
- package/ai-exported/migration/features/auxiliary-services.md +114 -0
- package/ai-exported/migration/features/bitcoin.md +88 -0
- package/ai-exported/migration/features/bridge.md +123 -0
- package/ai-exported/migration/features/dex.md +101 -0
- package/ai-exported/migration/features/migration.md +120 -0
- package/ai-exported/migration/features/money-market.md +97 -0
- package/ai-exported/migration/features/staking.md +109 -0
- package/ai-exported/migration/features/swap.md +118 -0
- package/ai-exported/migration/recipes.md +188 -0
- package/ai-exported/migration/reference/README.md +15 -0
- package/ai-exported/migration/reference/deleted-hooks.md +110 -0
- package/ai-exported/migration/reference/error-shape-crosswalk.md +144 -0
- package/ai-exported/migration/reference/renamed-hooks.md +66 -0
- package/dist/index.cjs +2642 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1550 -0
- package/dist/index.d.ts +1020 -2051
- package/dist/index.mjs +1594 -1532
- package/dist/index.mjs.map +1 -1
- package/package.json +20 -10
- package/src/contexts/index.ts +0 -3
- package/src/hooks/_mutationContract.test.ts +99 -0
- package/src/hooks/backend/README.md +2 -2
- package/src/hooks/backend/index.ts +13 -13
- package/src/hooks/backend/unwrapResult.ts +1 -0
- package/src/hooks/backend/useBackendAllMoneyMarketAssets.ts +13 -45
- package/src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts +29 -59
- package/src/hooks/backend/useBackendIntentByHash.ts +21 -47
- package/src/hooks/backend/useBackendIntentByTxHash.ts +23 -50
- package/src/hooks/backend/useBackendMoneyMarketAsset.ts +21 -54
- package/src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts +30 -57
- package/src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts +31 -58
- package/src/hooks/backend/useBackendMoneyMarketPosition.ts +22 -38
- package/src/hooks/backend/useBackendOrderbook.ts +27 -49
- package/src/hooks/backend/useBackendSubmitSwapTx.ts +30 -36
- package/src/hooks/backend/useBackendSubmitSwapTxStatus.ts +38 -58
- package/src/hooks/backend/useBackendUserIntents.ts +25 -63
- package/src/hooks/bitcoin/index.ts +9 -8
- package/src/hooks/bitcoin/useBitcoinBalance.ts +20 -5
- package/src/hooks/bitcoin/useExpiredUtxos.ts +26 -16
- package/src/hooks/bitcoin/useFundTradingWallet.ts +33 -30
- package/src/hooks/bitcoin/useRadfiAuth.ts +43 -40
- package/src/hooks/bitcoin/useRadfiSession.ts +53 -59
- package/src/hooks/bitcoin/useRadfiWithdraw.ts +35 -53
- package/src/hooks/bitcoin/useRenewUtxos.ts +30 -50
- package/src/hooks/bitcoin/useTradingWallet.ts +1 -1
- package/src/hooks/bitcoin/useTradingWalletBalance.ts +25 -14
- package/src/hooks/bridge/index.ts +5 -5
- package/src/hooks/bridge/useBridge.ts +29 -55
- package/src/hooks/bridge/useBridgeAllowance.ts +38 -38
- package/src/hooks/bridge/useBridgeApprove.ts +32 -57
- package/src/hooks/bridge/useGetBridgeableAmount.ts +23 -37
- package/src/hooks/bridge/useGetBridgeableTokens.ts +27 -50
- package/src/hooks/dex/index.ts +16 -16
- package/src/hooks/dex/useClaimRewards.ts +35 -54
- package/src/hooks/dex/useCreateDecreaseLiquidityParams.ts +7 -20
- package/src/hooks/dex/useCreateDepositParams.ts +7 -21
- package/src/hooks/dex/useCreateSupplyLiquidityParams.ts +13 -28
- package/src/hooks/dex/useCreateWithdrawParams.ts +7 -20
- package/src/hooks/dex/useDecreaseLiquidity.ts +40 -66
- package/src/hooks/dex/useDexAllowance.ts +29 -75
- package/src/hooks/dex/useDexApprove.ts +32 -43
- package/src/hooks/dex/useDexDeposit.ts +42 -49
- package/src/hooks/dex/useDexWithdraw.ts +32 -43
- package/src/hooks/dex/useLiquidityAmounts.ts +27 -84
- package/src/hooks/dex/usePoolBalances.ts +50 -72
- package/src/hooks/dex/usePoolData.ts +17 -43
- package/src/hooks/dex/usePools.ts +11 -38
- package/src/hooks/dex/usePositionInfo.ts +27 -62
- package/src/hooks/dex/useSupplyLiquidity.ts +80 -75
- package/src/hooks/index.ts +12 -10
- package/src/hooks/migrate/index.ts +13 -4
- package/src/hooks/migrate/useMigrateBaln.ts +42 -0
- package/src/hooks/migrate/useMigrateIcxToSoda.ts +44 -0
- package/src/hooks/migrate/useMigratebnUSD.ts +47 -0
- package/src/hooks/migrate/useMigrationAllowance.ts +76 -0
- package/src/hooks/migrate/useMigrationApprove.ts +66 -0
- package/src/hooks/migrate/useRevertMigrateSodaToIcx.ts +39 -0
- package/src/hooks/mm/index.ts +14 -12
- package/src/hooks/mm/useAToken.ts +25 -41
- package/src/hooks/mm/useATokensBalances.ts +29 -60
- package/src/hooks/mm/useBorrow.ts +38 -56
- package/src/hooks/mm/useMMAllowance.ts +37 -73
- package/src/hooks/mm/useMMApprove.ts +36 -43
- package/src/hooks/mm/useRepay.ts +33 -53
- package/src/hooks/mm/useReservesData.ts +12 -38
- package/src/hooks/mm/useReservesHumanized.ts +12 -31
- package/src/hooks/mm/useReservesList.ts +11 -31
- package/src/hooks/mm/useReservesUsdFormat.ts +15 -35
- package/src/hooks/mm/useSupply.ts +45 -51
- package/src/hooks/mm/useUserFormattedSummary.ts +32 -84
- package/src/hooks/mm/useUserReservesData.ts +27 -77
- package/src/hooks/mm/useWithdraw.ts +38 -54
- package/src/hooks/partner/index.ts +6 -0
- package/src/hooks/partner/useApproveToken.ts +42 -0
- package/src/hooks/partner/useFeeClaimSwap.ts +38 -0
- package/src/hooks/partner/useFetchAssetsBalances.ts +37 -0
- package/src/hooks/partner/useGetAutoSwapPreferences.ts +37 -0
- package/src/hooks/partner/useIsTokenApproved.ts +39 -0
- package/src/hooks/partner/useSetSwapPreference.ts +50 -0
- package/src/hooks/provider/index.ts +1 -2
- package/src/hooks/provider/useHubProvider.ts +1 -1
- package/src/hooks/recovery/index.ts +2 -0
- package/src/hooks/recovery/useHubAssetBalances.ts +43 -0
- package/src/hooks/recovery/useWithdrawHubAsset.ts +48 -0
- package/src/hooks/shared/index.ts +10 -6
- package/src/hooks/shared/types.ts +77 -0
- package/src/hooks/shared/unwrapResult.ts +19 -0
- package/src/hooks/shared/useDeriveUserWalletAddress.ts +22 -40
- package/src/hooks/shared/useEstimateGas.ts +18 -15
- package/src/hooks/shared/useGetUserHubWalletAddress.ts +25 -26
- package/src/hooks/shared/useRequestTrustline.ts +28 -61
- package/src/hooks/shared/useSafeMutation.test.ts +43 -0
- package/src/hooks/shared/useSafeMutation.ts +68 -0
- package/src/hooks/shared/useSodaxContext.ts +1 -1
- package/src/hooks/shared/useStellarTrustlineCheck.ts +30 -64
- package/src/hooks/shared/useXBalances.test.ts +113 -0
- package/src/hooks/shared/useXBalances.ts +61 -0
- package/src/hooks/staking/index.ts +18 -18
- package/src/hooks/staking/useCancelUnstake.ts +30 -41
- package/src/hooks/staking/useClaim.ts +27 -36
- package/src/hooks/staking/useConvertedAssets.ts +24 -34
- package/src/hooks/staking/useInstantUnstake.ts +33 -40
- package/src/hooks/staking/useInstantUnstakeAllowance.ts +37 -45
- package/src/hooks/staking/useInstantUnstakeApprove.ts +42 -42
- package/src/hooks/staking/useInstantUnstakeRatio.ts +24 -41
- package/src/hooks/staking/useStake.ts +32 -37
- package/src/hooks/staking/useStakeAllowance.ts +30 -43
- package/src/hooks/staking/useStakeApprove.ts +40 -40
- package/src/hooks/staking/useStakeRatio.ts +24 -40
- package/src/hooks/staking/useStakingConfig.ts +14 -27
- package/src/hooks/staking/useStakingInfo.ts +30 -38
- package/src/hooks/staking/useUnstake.ts +29 -43
- package/src/hooks/staking/useUnstakeAllowance.ts +37 -44
- package/src/hooks/staking/useUnstakeApprove.ts +40 -43
- package/src/hooks/staking/useUnstakingInfo.ts +29 -41
- package/src/hooks/staking/useUnstakingInfoWithPenalty.ts +31 -47
- package/src/hooks/swap/index.ts +8 -8
- package/src/hooks/swap/useCancelLimitOrder.ts +24 -41
- package/src/hooks/swap/useCancelSwap.ts +24 -33
- package/src/hooks/swap/useCreateLimitOrder.ts +29 -62
- package/src/hooks/swap/useQuote.ts +17 -43
- package/src/hooks/swap/useStatus.ts +22 -29
- package/src/hooks/swap/useSwap.ts +31 -49
- package/src/hooks/swap/useSwapAllowance.ts +38 -35
- package/src/hooks/swap/useSwapApprove.ts +48 -57
- package/src/index.ts +5 -3
- package/src/providers/SodaxProvider.tsx +17 -11
- package/src/providers/createSodaxQueryClient.ts +96 -0
- package/src/providers/index.ts +2 -1
- package/src/utils/dex-utils.ts +27 -5
- package/src/utils/index.ts +1 -1
- package/dist/index.d.mts +0 -2581
- package/dist/index.js +0 -2562
- package/dist/index.js.map +0 -1
- package/src/hooks/migrate/types.ts +0 -15
- package/src/hooks/migrate/useMigrate.tsx +0 -110
- package/src/hooks/migrate/useMigrationAllowance.tsx +0 -79
- package/src/hooks/migrate/useMigrationApprove.tsx +0 -129
- package/src/hooks/provider/useSpokeProvider.ts +0 -172
package/README.md
CHANGED
|
@@ -1,133 +1,69 @@
|
|
|
1
1
|
# @sodax/dapp-kit
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
High-level React hooks library for dApp developers. Wraps `@sodax/sdk` with React Query into feature-organized hooks. Used alongside `@sodax/wallet-sdk-react` (no direct dependency — shared types come from `@sodax/sdk`).
|
|
5
4
|
|
|
6
5
|
## Features
|
|
7
6
|
|
|
8
|
-
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
- Get USD formatted reserves data (`useReservesUsdFormat`)
|
|
20
|
-
- Get formatted user portfolio summary (`useUserFormattedSummary`)
|
|
21
|
-
|
|
22
|
-
- Swap/Intent
|
|
23
|
-
- Get quote for an intent order (`useQuote`)
|
|
24
|
-
- Create and submit an swap intent order (`useSwap`)
|
|
25
|
-
- Get status of an intent order (`useStatus`)
|
|
26
|
-
- Check token allowance (`useSwapAllowance`)
|
|
27
|
-
- Approve token spending (`useSwapApprove`)
|
|
28
|
-
- Cancel a swap intent order (`useCancelSwap`)
|
|
29
|
-
|
|
30
|
-
- Provider
|
|
31
|
-
- Get hub chain provider (`useHubProvider`)
|
|
32
|
-
- Get spoke chain provider (`useSpokeProvider`)
|
|
33
|
-
- Get wallet provider (`useWalletProvider`)
|
|
34
|
-
|
|
35
|
-
- Bridge
|
|
36
|
-
- Bridge tokens between chains (`useBridge`)
|
|
37
|
-
- Check token allowance for bridging (`useBridgeAllowance`)
|
|
38
|
-
- Approve source token for bridging (`useBridgeApprove`)
|
|
39
|
-
- Get max amount available to be bridged (`useGetBridgeableAmount`)
|
|
40
|
-
- Get available destination tokens based on provided source token (`useGetBridgeableTokens`)
|
|
41
|
-
|
|
42
|
-
- Shared
|
|
43
|
-
- Derive user wallet address for hub abstraction (`useDeriveUserWalletAddress`)
|
|
44
|
-
- Check if Stellar trustline is established for an asset (`useStellarTrustlineCheck`)
|
|
45
|
-
- Request creation of Stellar trustline line for an asset (`useRequestTrustline`)
|
|
46
|
-
|
|
47
|
-
- Staking
|
|
48
|
-
- Stake SODA tokens to receive xSODA shares (`useStake`)
|
|
49
|
-
- Unstake xSODA shares (`useUnstake`)
|
|
50
|
-
- Instant unstake xSODA shares with penalty (`useInstantUnstake`)
|
|
51
|
-
- Claim unstaked SODA tokens after unstaking period (`useClaim`)
|
|
52
|
-
- Cancel unstake request (`useCancelUnstake`)
|
|
53
|
-
- Check SODA token allowance for staking (`useStakeAllowance`)
|
|
54
|
-
- Approve SODA token spending for staking (`useStakeApprove`)
|
|
55
|
-
- Check xSODA token allowance for unstaking (`useUnstakeAllowance`)
|
|
56
|
-
- Approve xSODA token spending for unstaking (`useUnstakeApprove`)
|
|
57
|
-
- Check xSODA token allowance for instant unstaking (`useInstantUnstakeAllowance`)
|
|
58
|
-
- Approve xSODA token spending for instant unstaking (`useInstantUnstakeApprove`)
|
|
59
|
-
- Get comprehensive staking information (`useStakingInfo`)
|
|
60
|
-
- Get unstaking information with penalty details (`useUnstakingInfoWithPenalty`)
|
|
61
|
-
- Get unstaking information (`useUnstakingInfo`)
|
|
62
|
-
- Get staking configuration (`useStakingConfig`)
|
|
63
|
-
- Get stake ratio (SODA to xSODA conversion rate) (`useStakeRatio`)
|
|
64
|
-
- Get instant unstake ratio (xSODA to SODA conversion rate with penalty) (`useInstantUnstakeRatio`)
|
|
65
|
-
- Get converted assets amount for xSODA shares (`useConvertedAssets`)
|
|
66
|
-
|
|
67
|
-
- DEX (Decentralized Exchange)
|
|
68
|
-
- Get available pools list (`usePools`)
|
|
69
|
-
- Get pool data for a selected pool (`usePoolData`)
|
|
70
|
-
- Get token balances for pool tokens (`usePoolBalances`)
|
|
71
|
-
- Get position information by token ID (`usePositionInfo`)
|
|
72
|
-
- Deposit tokens to a pool (`useDexDeposit`)
|
|
73
|
-
- Withdraw tokens from a pool (`useDexWithdraw`)
|
|
74
|
-
- Check token allowance for DEX operations (`useDexAllowance`)
|
|
75
|
-
- Approve token spending for DEX operations (`useDexApprove`)
|
|
76
|
-
- Calculate liquidity amounts based on price range (`useLiquidityAmounts`)
|
|
77
|
-
- Supply liquidity to a pool (`useSupplyLiquidity`)
|
|
78
|
-
- Decrease liquidity from a position (`useDecreaseLiquidity`)
|
|
7
|
+
- **Swap/Intent** — `useQuote`, `useSwap`, `useSwapAllowance`, `useSwapApprove`, `useCancelSwap`, `useCreateLimitOrder`, `useCancelLimitOrder`, `useStatus`
|
|
8
|
+
- **Bridge** — `useBridge`, `useBridgeAllowance`, `useBridgeApprove`, `useGetBridgeableAmount`, `useGetBridgeableTokens`
|
|
9
|
+
- **Money Market** — `useSupply`, `useWithdraw`, `useBorrow`, `useRepay`, `useMMAllowance`, `useMMApprove`, plus reserves data hooks
|
|
10
|
+
- **Staking** — `useStake`, `useUnstake`, `useInstantUnstake`, `useClaim`, `useCancelUnstake`, approval hooks, info/config/ratio queries
|
|
11
|
+
- **DEX** — `useDexDeposit`, `useDexWithdraw`, `useSupplyLiquidity`, `useDecreaseLiquidity`, `useClaimRewards`, pool/position queries, param builders
|
|
12
|
+
- **Migration** — `useMigrateIcxToSoda`, `useRevertMigrateSodaToIcx`, `useMigratebnUSD`, `useMigrateBaln`, `useMigrationApprove`, `useMigrationAllowance`
|
|
13
|
+
- **Bitcoin (Radfi)** — `useRadfiAuth`, `useRadfiSession`, `useTradingWallet`, `useTradingWalletBalance`, `useBitcoinBalance`, `useFundTradingWallet`, `useRadfiWithdraw`, `useExpiredUtxos`, `useRenewUtxos`
|
|
14
|
+
- **Partner** — `useFetchAssetsBalances`, `useGetAutoSwapPreferences`, `useIsTokenApproved`, `useApproveToken`, `useSetSwapPreference`, `useFeeClaimSwap`
|
|
15
|
+
- **Recovery** — `useHubAssetBalances`, `useWithdrawHubAsset`
|
|
16
|
+
- **Backend Queries** — Intent tracking, orderbook, money market position queries
|
|
17
|
+
- **Shared** — `useXBalances`, `useDeriveUserWalletAddress`, `useGetUserHubWalletAddress`, `useStellarTrustlineCheck`, `useRequestTrustline`, `useEstimateGas`
|
|
79
18
|
|
|
80
19
|
## Installation
|
|
81
20
|
|
|
82
21
|
```bash
|
|
83
|
-
|
|
84
|
-
#
|
|
85
|
-
|
|
86
|
-
# or
|
|
87
|
-
pnpm add @sodax/dapp-kit
|
|
22
|
+
pnpm add @sodax/dapp-kit @tanstack/react-query
|
|
23
|
+
# Optional: wallet connectivity
|
|
24
|
+
pnpm add @sodax/wallet-sdk-react
|
|
88
25
|
```
|
|
89
26
|
|
|
90
27
|
## Quick Start
|
|
91
28
|
|
|
92
|
-
1.
|
|
29
|
+
### 1. Set up providers
|
|
93
30
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
```
|
|
31
|
+
RPC URLs are injected through `config.chains`. `SodaxProvider` is the outermost wrapper; `QueryClientProvider` wraps everything inside it.
|
|
32
|
+
|
|
33
|
+
```tsx
|
|
34
|
+
// providers.tsx
|
|
35
|
+
import { QueryClientProvider } from '@tanstack/react-query';
|
|
36
|
+
import { SodaxProvider, createSodaxQueryClient } from '@sodax/dapp-kit';
|
|
37
|
+
import { SodaxWalletProvider, type SodaxWalletConfig } from '@sodax/wallet-sdk-react';
|
|
38
|
+
import { ChainKeys, type DeepPartial, type SodaxConfig } from '@sodax/sdk';
|
|
97
39
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
// Other chains
|
|
119
|
-
'0x1.icon': 'https://ctz.solidwallet.io/api/v3',
|
|
120
|
-
solana: 'https://solana-mainnet.g.alchemy.com/v2/your-api-key',
|
|
121
|
-
sui: 'https://fullnode.mainnet.sui.io',
|
|
122
|
-
'injective-1': 'https://sentry.tm.injective.network:26657',
|
|
40
|
+
const queryClient = createSodaxQueryClient();
|
|
41
|
+
|
|
42
|
+
const sodaxConfig: DeepPartial<SodaxConfig> = {
|
|
43
|
+
chains: {
|
|
44
|
+
[ChainKeys.SONIC_MAINNET]: { rpcUrl: 'https://sonic-rpc.publicnode.com' },
|
|
45
|
+
[ChainKeys.BSC_MAINNET]: { rpcUrl: 'https://bsc-dataseed.binance.org' },
|
|
46
|
+
[ChainKeys.BASE_MAINNET]: { rpcUrl: 'https://base.drpc.org' },
|
|
47
|
+
[ChainKeys.ARBITRUM_MAINNET]: { rpcUrl: 'https://arb1.arbitrum.io/rpc' },
|
|
48
|
+
// Add chains your dApp needs
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const walletConfig: SodaxWalletConfig = {
|
|
53
|
+
EVM: {
|
|
54
|
+
chains: {
|
|
55
|
+
[ChainKeys.BSC_MAINNET]: { rpcUrl: 'https://bsc-dataseed.binance.org' },
|
|
56
|
+
[ChainKeys.BASE_MAINNET]: { rpcUrl: 'https://base.drpc.org' },
|
|
57
|
+
},
|
|
58
|
+
},
|
|
123
59
|
};
|
|
124
60
|
|
|
125
|
-
function
|
|
61
|
+
export function Providers({ children }: { children: React.ReactNode }) {
|
|
126
62
|
return (
|
|
127
|
-
<SodaxProvider
|
|
63
|
+
<SodaxProvider config={sodaxConfig}>
|
|
128
64
|
<QueryClientProvider client={queryClient}>
|
|
129
|
-
<SodaxWalletProvider
|
|
130
|
-
|
|
65
|
+
<SodaxWalletProvider config={walletConfig}>
|
|
66
|
+
{children}
|
|
131
67
|
</SodaxWalletProvider>
|
|
132
68
|
</QueryClientProvider>
|
|
133
69
|
</SodaxProvider>
|
|
@@ -135,354 +71,296 @@ function App() {
|
|
|
135
71
|
}
|
|
136
72
|
```
|
|
137
73
|
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
```typescript
|
|
141
|
-
// Connect Wallet Operations
|
|
142
|
-
// Money Market Operations
|
|
143
|
-
import { useSupply, useWithdraw, useBorrow, useRepay, useUserReservesData, useMMAllowance, useMMApprove } from '@sodax/dapp-kit';
|
|
144
|
-
import { parseUnits } from 'viem';
|
|
145
|
-
import { useMemo, useState } from 'react';
|
|
146
|
-
|
|
147
|
-
function MoneyMarketComponent() {
|
|
148
|
-
const [amount, setAmount] = useState<string>('');
|
|
149
|
-
const spokeProvider = useSpokeProvider(chainId, walletProvider);
|
|
150
|
-
|
|
151
|
-
// Supply tokens
|
|
152
|
-
const supplyParams = useMemo(() => {
|
|
153
|
-
if (!amount) return undefined;
|
|
154
|
-
return {
|
|
155
|
-
token: token.address,
|
|
156
|
-
amount: parseUnits(amount, token.decimals),
|
|
157
|
-
action: 'supply' as const,
|
|
158
|
-
};
|
|
159
|
-
}, [token.address, token.decimals, amount]);
|
|
160
|
-
|
|
161
|
-
const { data: hasSupplyAllowed, isLoading: isSupplyAllowanceLoading } = useMMAllowance(supplyParams, spokeProvider);
|
|
162
|
-
const { mutateAsync: approveSupply, isPending: isApprovingSupply, error: approveSupplyError } = useMMApprove();
|
|
163
|
-
const { mutateAsync: supply, isPending: isSupplying, error: supplyError } = useSupply();
|
|
164
|
-
|
|
165
|
-
const handleApproveSupply = async () => {
|
|
166
|
-
if (!spokeProvider || !supplyParams) return;
|
|
167
|
-
try {
|
|
168
|
-
await approveSupply({ params: supplyParams, spokeProvider });
|
|
169
|
-
} catch (err) {
|
|
170
|
-
console.error('Error approving supply:', err);
|
|
171
|
-
}
|
|
172
|
-
};
|
|
74
|
+
### 2. Get a wallet provider
|
|
173
75
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
await supply({ params: supplyParams, spokeProvider });
|
|
178
|
-
} catch (err) {
|
|
179
|
-
console.error('Error supplying:', err);
|
|
180
|
-
}
|
|
181
|
-
};
|
|
76
|
+
```tsx
|
|
77
|
+
import { useWalletProvider } from '@sodax/wallet-sdk-react';
|
|
78
|
+
import { ChainKeys } from '@sodax/sdk';
|
|
182
79
|
|
|
183
|
-
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
amount: parseUnits(amount, 18), // vault token on hub chain decimals is 18
|
|
189
|
-
action: 'withdraw' as const,
|
|
190
|
-
};
|
|
191
|
-
}, [token.address, amount]);
|
|
192
|
-
|
|
193
|
-
const { data: hasWithdrawAllowed, isLoading: isWithdrawAllowanceLoading } = useMMAllowance(withdrawParams, spokeProvider);
|
|
194
|
-
const { data: hasWithdrawAllowed, isLoading: isWithdrawAllowanceLoading } = useMMAllowance({ params: withdrawParams, spokeProvider });
|
|
195
|
-
|
|
196
|
-
const { mutateAsync: approveWithdraw, isPending: isApprovingWithdraw, error: approveWithdrawError } = useMMApprove();
|
|
197
|
-
const { mutateAsync: withdraw, isPending: isWithdrawing, error: withdrawError } = useWithdraw();
|
|
198
|
-
|
|
199
|
-
const handleApproveWithdraw = async () => {
|
|
200
|
-
if (!spokeProvider || !withdrawParams) return;
|
|
201
|
-
try {
|
|
202
|
-
await approveWithdraw({ params: withdrawParams, spokeProvider });
|
|
203
|
-
} catch (err) {
|
|
204
|
-
console.error('Error approving withdraw:', err);
|
|
205
|
-
}
|
|
206
|
-
};
|
|
80
|
+
function MyFeature() {
|
|
81
|
+
const walletProvider = useWalletProvider(ChainKeys.BSC_MAINNET);
|
|
82
|
+
// undefined until wallet is connected
|
|
83
|
+
}
|
|
84
|
+
```
|
|
207
85
|
|
|
208
|
-
|
|
209
|
-
if (!spokeProvider || !withdrawParams) return;
|
|
210
|
-
try {
|
|
211
|
-
await withdraw({ params: withdrawParams, spokeProvider });
|
|
212
|
-
} catch (err) {
|
|
213
|
-
console.error('Error withdrawing:', err);
|
|
214
|
-
}
|
|
215
|
-
};
|
|
86
|
+
### 3. Use feature hooks
|
|
216
87
|
|
|
217
|
-
|
|
218
|
-
const borrowParams = useMemo(() => {
|
|
219
|
-
if (!amount) return undefined;
|
|
220
|
-
return {
|
|
221
|
-
token: token.address,
|
|
222
|
-
amount: parseUnits(amount, 18),
|
|
223
|
-
action: 'borrow' as const,
|
|
224
|
-
};
|
|
225
|
-
}, [token.address, amount]);
|
|
226
|
-
|
|
227
|
-
const { data: hasBorrowAllowed, isLoading: isBorrowAllowanceLoading } = useMMAllowance({ params: borrowParams, spokeProvider });
|
|
228
|
-
const { mutateAsync: approveBorrow, isPending: isApprovingBorrow, error: approveBorrowError } = useMMApprove();
|
|
229
|
-
const { mutateAsync: borrow, isPending: isBorrowing, error: borrowError } = useBorrow();
|
|
230
|
-
|
|
231
|
-
const handleApproveBorrow = async () => {
|
|
232
|
-
if (!spokeProvider || !borrowParams) return;
|
|
233
|
-
try {
|
|
234
|
-
await approveBorrow({ params: borrowParams, spokeProvider });
|
|
235
|
-
} catch (err) {
|
|
236
|
-
console.error('Error approving borrow:', err);
|
|
237
|
-
}
|
|
238
|
-
};
|
|
88
|
+
All mutation hooks accept no arguments at initialization. Domain inputs (params, walletProvider) flow through `mutate(vars)`:
|
|
239
89
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
console.error('Error borrowing:', err);
|
|
246
|
-
}
|
|
247
|
-
};
|
|
90
|
+
```tsx
|
|
91
|
+
import { useSwap } from '@sodax/dapp-kit';
|
|
92
|
+
import { useWalletProvider } from '@sodax/wallet-sdk-react';
|
|
93
|
+
import { ChainKeys } from '@sodax/sdk';
|
|
94
|
+
import type { CreateIntentParams } from '@sodax/sdk';
|
|
248
95
|
|
|
249
|
-
|
|
250
|
-
const
|
|
251
|
-
|
|
252
|
-
return {
|
|
253
|
-
token: token.address,
|
|
254
|
-
amount: parseUnits(amount, token.decimals),
|
|
255
|
-
action: 'repay' as const,
|
|
256
|
-
};
|
|
257
|
-
}, [token.address, token.decimals, amount]);
|
|
258
|
-
|
|
259
|
-
const { data: hasRepayAllowed, isLoading: isRepayAllowanceLoading } = useMMAllowance({ params: repayParams, spokeProvider });
|
|
260
|
-
const { mutateAsync: approveRepay, isPending: isApprovingRepay, error: approveRepayError } = useMMApprove();
|
|
261
|
-
const { mutateAsync: repay, isPending: isRepaying, error: repayError } = useRepay();
|
|
262
|
-
|
|
263
|
-
const handleApproveRepay = async () => {
|
|
264
|
-
if (!spokeProvider || !repayParams) return;
|
|
265
|
-
try {
|
|
266
|
-
await approveRepay({ params: repayParams, spokeProvider });
|
|
267
|
-
} catch (err) {
|
|
268
|
-
console.error('Error approving repay:', err);
|
|
269
|
-
}
|
|
270
|
-
};
|
|
96
|
+
function SwapButton({ intentParams }: { intentParams: CreateIntentParams }) {
|
|
97
|
+
const walletProvider = useWalletProvider(ChainKeys.BSC_MAINNET);
|
|
98
|
+
const { mutateAsyncSafe: swap, isPending } = useSwap();
|
|
271
99
|
|
|
272
|
-
const
|
|
273
|
-
if (!
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
100
|
+
const handleSwap = async () => {
|
|
101
|
+
if (!walletProvider) return;
|
|
102
|
+
const result = await swap({ params: intentParams, walletProvider });
|
|
103
|
+
if (!result.ok) {
|
|
104
|
+
alert(result.error instanceof Error ? result.error.message : 'Swap failed');
|
|
105
|
+
return;
|
|
278
106
|
}
|
|
107
|
+
console.log('Swap submitted!', result.value);
|
|
279
108
|
};
|
|
280
109
|
|
|
281
|
-
// Get user's supplied assets
|
|
282
|
-
const { address } = useXAccount(chainId);
|
|
283
|
-
const { data: userReserves } = useUserReservesData({ spokeChainId: chainId, userAddress: address });
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
// Wallet Address Derivation
|
|
287
|
-
import { useDeriveUserWalletAddress, useSpokeProvider } from '@sodax/dapp-kit';
|
|
288
|
-
|
|
289
|
-
function WalletAddressComponent() {
|
|
290
|
-
const spokeProvider = useSpokeProvider(chainId, walletProvider);
|
|
291
|
-
|
|
292
|
-
// Derive user wallet address for hub abstraction
|
|
293
|
-
const { data: derivedAddress, isLoading, error } = useDeriveUserWalletAddress(spokeProvider, userAddress);
|
|
294
|
-
|
|
295
110
|
return (
|
|
296
|
-
<
|
|
297
|
-
{
|
|
298
|
-
|
|
299
|
-
{derivedAddress && <div>Derived Address: {derivedAddress}</div>}
|
|
300
|
-
</div>
|
|
111
|
+
<button onClick={handleSwap} disabled={isPending || !walletProvider}>
|
|
112
|
+
{isPending ? 'Swapping...' : 'Swap'}
|
|
113
|
+
</button>
|
|
301
114
|
);
|
|
302
115
|
}
|
|
303
|
-
|
|
304
|
-
// Swap Operations
|
|
305
|
-
import { useQuote, useSwap, useStatus } from '@sodax/dapp-kit';
|
|
306
|
-
|
|
307
|
-
function SwapComponent() {
|
|
308
|
-
// Get quote for an intent order
|
|
309
|
-
const { data: quote, isLoading: isQuoteLoading } = useQuote({
|
|
310
|
-
token_src: '0x...',
|
|
311
|
-
token_src_blockchain_id: '0xa86a.avax',
|
|
312
|
-
token_dst: '0x...',
|
|
313
|
-
token_dst_blockchain_id: '0xa4b1.arbitrum',
|
|
314
|
-
amount: '1000000000000000000',
|
|
315
|
-
quote_type: 'exact_input',
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
// Create and submit an intent order
|
|
319
|
-
const { mutateAsync: swap, isPending: isCreating } = useSwap();
|
|
320
|
-
const handleSwap = async () => {
|
|
321
|
-
const order = await swap({
|
|
322
|
-
token_src: '0x...',
|
|
323
|
-
token_src_blockchain_id: '0xa86a.avax',
|
|
324
|
-
token_dst: '0x...',
|
|
325
|
-
token_dst_blockchain_id: '0xa4b1.arbitrum',
|
|
326
|
-
amount: '1000000000000000000',
|
|
327
|
-
quote_type: 'exact_input',
|
|
328
|
-
});
|
|
329
|
-
};
|
|
330
|
-
|
|
331
|
-
// Get status of an intent order
|
|
332
|
-
const { data: orderStatus } = useStatus('0x...');
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
// Bridge Operations
|
|
336
|
-
import { useBridge, useBridgeAllowance, useBridgeApprove, useGetBridgeableAmount, useGetBridgeableTokens } from '@sodax/dapp-kit';
|
|
337
|
-
|
|
338
|
-
function BridgeComponent() {
|
|
339
|
-
const spokeProvider = useSpokeProvider(chainId, walletProvider);
|
|
340
|
-
|
|
341
|
-
// Get available destination tokens for bridging
|
|
342
|
-
const { data: bridgeableTokens, isLoading: isTokensLoading } = useGetBridgeableTokens(
|
|
343
|
-
'0x2105.base', // from chain
|
|
344
|
-
'0x89.polygon', // to chain
|
|
345
|
-
'0x...' // source token address
|
|
346
|
-
);
|
|
347
|
-
|
|
348
|
-
// Get maximum amount available to bridge
|
|
349
|
-
const { data: bridgeableAmount } = useGetBridgeableAmount(
|
|
350
|
-
{ address: '0x...', xChainId: '0x2105.base' }, // from token
|
|
351
|
-
{ address: '0x...', xChainId: '0x89.polygon' } // to token
|
|
352
|
-
);
|
|
353
|
-
|
|
354
|
-
// Check token allowance for bridge
|
|
355
|
-
const { data: hasAllowed } = useBridgeAllowance(bridgeParams, spokeProvider);
|
|
356
|
-
|
|
357
|
-
// Approve tokens for bridge
|
|
358
|
-
const { approve: approveBridge, isLoading: isApproving } = useBridgeApprove(spokeProvider);
|
|
359
|
-
const handleApprove = async () => {
|
|
360
|
-
await approveBridge(bridgeParams);
|
|
361
|
-
};
|
|
362
|
-
|
|
363
|
-
// Execute bridge transaction
|
|
364
|
-
const { mutateAsync: bridge, isPending: isBridging } = useBridge(spokeProvider);
|
|
365
|
-
const handleBridge = async () => {
|
|
366
|
-
const result = await bridge({
|
|
367
|
-
srcChainId: '0x2105.base',
|
|
368
|
-
srcAsset: '0x...',
|
|
369
|
-
amount: 1000n,
|
|
370
|
-
dstChainId: '0x89.polygon',
|
|
371
|
-
dstAsset: '0x...',
|
|
372
|
-
recipient: '0x...'
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
console.log('Bridge transaction hashes:', {
|
|
376
|
-
spokeTxHash: result.value[0],
|
|
377
|
-
hubTxHash: result.value[1]
|
|
378
|
-
});
|
|
379
|
-
};
|
|
380
|
-
}
|
|
381
116
|
```
|
|
382
117
|
|
|
383
118
|
## Requirements
|
|
384
119
|
|
|
385
120
|
- Node.js >= 18.0.0
|
|
386
|
-
- React >=
|
|
121
|
+
- React >= 18
|
|
387
122
|
- TypeScript
|
|
388
123
|
|
|
389
124
|
## API Reference
|
|
390
125
|
|
|
391
|
-
###
|
|
392
|
-
|
|
393
|
-
- [`SodaxProvider`](
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
- [`
|
|
399
|
-
- [`
|
|
400
|
-
- [`
|
|
401
|
-
- [`
|
|
402
|
-
- [`
|
|
403
|
-
- [`
|
|
404
|
-
- [`
|
|
405
|
-
- [`
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
- [`
|
|
410
|
-
- [`
|
|
411
|
-
- [`
|
|
412
|
-
-
|
|
413
|
-
-
|
|
414
|
-
-
|
|
415
|
-
- [`
|
|
416
|
-
- [`
|
|
417
|
-
- [`
|
|
418
|
-
- [`
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
- [`
|
|
422
|
-
- [`
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
- [`useBridge()`](
|
|
427
|
-
- [`useBridgeAllowance()`](
|
|
428
|
-
- [`useBridgeApprove()`](
|
|
429
|
-
- [`useGetBridgeableAmount()`](
|
|
430
|
-
- [`useGetBridgeableTokens()`](
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
- [`
|
|
435
|
-
- [`
|
|
436
|
-
- [`
|
|
437
|
-
- [`
|
|
438
|
-
- [`
|
|
439
|
-
- [`
|
|
440
|
-
- [`
|
|
441
|
-
- [`
|
|
442
|
-
- [`
|
|
443
|
-
- [`
|
|
444
|
-
- [`
|
|
445
|
-
- [`
|
|
446
|
-
- [`
|
|
447
|
-
- [`
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
- [`
|
|
451
|
-
- [`
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
126
|
+
### Provider
|
|
127
|
+
|
|
128
|
+
- [`SodaxProvider`](src/providers/SodaxProvider.tsx) — Wraps your app, creates the `Sodax` SDK instance. Accepts `config?: DeepPartial<SodaxConfig>`.
|
|
129
|
+
- [`createSodaxQueryClient()`](src/providers/createSodaxQueryClient.ts) — Factory for a `QueryClient` with global mutation observability (`onMutationError` hook, `meta.silent` opt-out).
|
|
130
|
+
|
|
131
|
+
### Swap Hooks
|
|
132
|
+
|
|
133
|
+
- [`useQuote()`](src/hooks/swap/useQuote.ts) — Real-time quote (auto-refreshes every 3s)
|
|
134
|
+
- [`useSwap()`](src/hooks/swap/useSwap.ts) — Submit a cross-chain swap intent
|
|
135
|
+
- [`useSwapAllowance()`](src/hooks/swap/useSwapAllowance.ts) — Check token approval
|
|
136
|
+
- [`useSwapApprove()`](src/hooks/swap/useSwapApprove.ts) — Approve token spending
|
|
137
|
+
- [`useStatus()`](src/hooks/swap/useStatus.ts) — Track intent execution status
|
|
138
|
+
- [`useCancelSwap()`](src/hooks/swap/useCancelSwap.ts) — Cancel a pending swap
|
|
139
|
+
- [`useCreateLimitOrder()`](src/hooks/swap/useCreateLimitOrder.ts) — Create a limit order (no deadline)
|
|
140
|
+
- [`useCancelLimitOrder()`](src/hooks/swap/useCancelLimitOrder.ts) — Cancel a limit order
|
|
141
|
+
|
|
142
|
+
### Money Market Hooks
|
|
143
|
+
|
|
144
|
+
- [`useSupply()`](src/hooks/mm/useSupply.ts) — Supply collateral
|
|
145
|
+
- [`useWithdraw()`](src/hooks/mm/useWithdraw.ts) — Withdraw supplied tokens
|
|
146
|
+
- [`useBorrow()`](src/hooks/mm/useBorrow.ts) — Borrow against collateral
|
|
147
|
+
- [`useRepay()`](src/hooks/mm/useRepay.ts) — Repay borrowed tokens
|
|
148
|
+
- [`useMMAllowance()`](src/hooks/mm/useMMAllowance.ts) — Check approval (auto-skips for borrow/withdraw)
|
|
149
|
+
- [`useMMApprove()`](src/hooks/mm/useMMApprove.ts) — Approve token spending
|
|
150
|
+
- [`useReservesData()`](src/hooks/mm/useReservesData.ts) — All reserve data
|
|
151
|
+
- [`useReservesHumanized()`](src/hooks/mm/useReservesHumanized.ts) — Reserves in decimal-normalized format
|
|
152
|
+
- [`useReservesList()`](src/hooks/mm/useReservesList.ts) — List of reserve asset addresses
|
|
153
|
+
- [`useReservesUsdFormat()`](src/hooks/mm/useReservesUsdFormat.ts) — Reserves with USD values
|
|
154
|
+
- [`useUserFormattedSummary()`](src/hooks/mm/useUserFormattedSummary.ts) — User portfolio summary (health factor, collateral, debt)
|
|
155
|
+
- [`useUserReservesData()`](src/hooks/mm/useUserReservesData.ts) — User reserve positions
|
|
156
|
+
- [`useAToken()`](src/hooks/mm/useAToken.ts) — aToken metadata
|
|
157
|
+
- [`useATokensBalances()`](src/hooks/mm/useATokensBalances.ts) — aToken balances
|
|
158
|
+
|
|
159
|
+
### Bridge Hooks
|
|
160
|
+
|
|
161
|
+
- [`useBridge()`](src/hooks/bridge/useBridge.ts) — Execute a cross-chain bridge transfer
|
|
162
|
+
- [`useBridgeAllowance()`](src/hooks/bridge/useBridgeAllowance.ts) — Check token approval
|
|
163
|
+
- [`useBridgeApprove()`](src/hooks/bridge/useBridgeApprove.ts) — Approve token spending
|
|
164
|
+
- [`useGetBridgeableAmount()`](src/hooks/bridge/useGetBridgeableAmount.ts) — Max bridgeable amount between two tokens
|
|
165
|
+
- [`useGetBridgeableTokens()`](src/hooks/bridge/useGetBridgeableTokens.ts) — Tokens bridgeable to a destination chain
|
|
166
|
+
|
|
167
|
+
### Staking Hooks
|
|
168
|
+
|
|
169
|
+
- [`useStake()`](src/hooks/staking/useStake.ts) — Stake SODA, receive xSODA
|
|
170
|
+
- [`useUnstake()`](src/hooks/staking/useUnstake.ts) — Request unstake (waiting period)
|
|
171
|
+
- [`useInstantUnstake()`](src/hooks/staking/useInstantUnstake.ts) — Instant unstake with slippage
|
|
172
|
+
- [`useClaim()`](src/hooks/staking/useClaim.ts) — Claim SODA after waiting period
|
|
173
|
+
- [`useCancelUnstake()`](src/hooks/staking/useCancelUnstake.ts) — Cancel pending unstake
|
|
174
|
+
- [`useStakeApprove()`](src/hooks/staking/useStakeApprove.ts) — Approve SODA for staking
|
|
175
|
+
- [`useUnstakeApprove()`](src/hooks/staking/useUnstakeApprove.ts) — Approve xSODA for unstaking
|
|
176
|
+
- [`useInstantUnstakeApprove()`](src/hooks/staking/useInstantUnstakeApprove.ts) — Approve xSODA for instant unstaking
|
|
177
|
+
- [`useStakeAllowance()`](src/hooks/staking/useStakeAllowance.ts) — Check SODA approval
|
|
178
|
+
- [`useUnstakeAllowance()`](src/hooks/staking/useUnstakeAllowance.ts) — Check xSODA approval for unstaking
|
|
179
|
+
- [`useInstantUnstakeAllowance()`](src/hooks/staking/useInstantUnstakeAllowance.ts) — Check xSODA approval for instant unstaking
|
|
180
|
+
- [`useStakingInfo()`](src/hooks/staking/useStakingInfo.ts) — User staking position
|
|
181
|
+
- [`useUnstakingInfo()`](src/hooks/staking/useUnstakingInfo.ts) — Pending unstake requests
|
|
182
|
+
- [`useUnstakingInfoWithPenalty()`](src/hooks/staking/useUnstakingInfoWithPenalty.ts) — Unstake requests with penalty calcs
|
|
183
|
+
- [`useStakingConfig()`](src/hooks/staking/useStakingConfig.ts) — Unstaking period, max penalty
|
|
184
|
+
- [`useStakeRatio()`](src/hooks/staking/useStakeRatio.ts) — SODA-to-xSODA exchange rate
|
|
185
|
+
- [`useInstantUnstakeRatio()`](src/hooks/staking/useInstantUnstakeRatio.ts) — Instant unstake rate
|
|
186
|
+
- [`useConvertedAssets()`](src/hooks/staking/useConvertedAssets.ts) — xSODA to SODA conversion
|
|
187
|
+
|
|
188
|
+
### DEX Hooks
|
|
189
|
+
|
|
190
|
+
- [`usePools()`](src/hooks/dex/usePools.ts) — List available pools
|
|
191
|
+
- [`usePoolData()`](src/hooks/dex/usePoolData.ts) — Pool details (price, tick, liquidity)
|
|
192
|
+
- [`usePoolBalances()`](src/hooks/dex/usePoolBalances.ts) — User pool token balances
|
|
193
|
+
- [`usePositionInfo()`](src/hooks/dex/usePositionInfo.ts) — Position details by token ID
|
|
194
|
+
- [`useDexDeposit()`](src/hooks/dex/useDexDeposit.ts) — Deposit assets into pool tokens
|
|
195
|
+
- [`useDexWithdraw()`](src/hooks/dex/useDexWithdraw.ts) — Withdraw assets from pool tokens
|
|
196
|
+
- [`useDexAllowance()`](src/hooks/dex/useDexAllowance.ts) — Check approval for deposit
|
|
197
|
+
- [`useDexApprove()`](src/hooks/dex/useDexApprove.ts) — Approve token spending
|
|
198
|
+
- [`useLiquidityAmounts()`](src/hooks/dex/useLiquidityAmounts.ts) — Token amounts for a tick range
|
|
199
|
+
- [`useSupplyLiquidity()`](src/hooks/dex/useSupplyLiquidity.ts) — Supply liquidity to a position
|
|
200
|
+
- [`useDecreaseLiquidity()`](src/hooks/dex/useDecreaseLiquidity.ts) — Remove liquidity
|
|
201
|
+
- [`useClaimRewards()`](src/hooks/dex/useClaimRewards.ts) — Claim trading fees
|
|
202
|
+
- [`useCreateDepositParams()`](src/hooks/dex/useCreateDepositParams.ts) — Build deposit params with ERC-4626 conversion
|
|
203
|
+
- [`useCreateWithdrawParams()`](src/hooks/dex/useCreateWithdrawParams.ts) — Build withdraw params
|
|
204
|
+
- [`useCreateSupplyLiquidityParams()`](src/hooks/dex/useCreateSupplyLiquidityParams.ts) — Build tick range + liquidity params
|
|
205
|
+
- [`useCreateDecreaseLiquidityParams()`](src/hooks/dex/useCreateDecreaseLiquidityParams.ts) — Build decrease params from position state
|
|
206
|
+
|
|
207
|
+
### Migration Hooks
|
|
208
|
+
|
|
209
|
+
- [`useMigrateIcxToSoda()`](src/hooks/migrate/useMigrateIcxToSoda.ts) — ICX/wICX (ICON) → SODA (Sonic)
|
|
210
|
+
- [`useRevertMigrateSodaToIcx()`](src/hooks/migrate/useRevertMigrateSodaToIcx.ts) — SODA (Sonic) → wICX (ICON)
|
|
211
|
+
- [`useMigratebnUSD()`](src/hooks/migrate/useMigratebnUSD.ts) — Legacy bnUSD ↔ new bnUSD (bidirectional)
|
|
212
|
+
- [`useMigrateBaln()`](src/hooks/migrate/useMigrateBaln.ts) — BALN (ICON) → SODA with optional lock period
|
|
213
|
+
- [`useMigrationApprove()`](src/hooks/migrate/useMigrationApprove.ts) — Approve token spending before migration
|
|
214
|
+
- [`useMigrationAllowance()`](src/hooks/migrate/useMigrationAllowance.ts) — Check if approval is needed
|
|
215
|
+
|
|
216
|
+
### Bitcoin (Radfi) Hooks
|
|
217
|
+
|
|
218
|
+
- [`useRadfiSession()`](src/hooks/bitcoin/useRadfiSession.ts) — Manage Radfi session (login, auto-refresh)
|
|
219
|
+
- [`useRadfiAuth()`](src/hooks/bitcoin/useRadfiAuth.ts) — Authenticate with Radfi via BIP322 signing
|
|
220
|
+
- [`useTradingWallet()`](src/hooks/bitcoin/useTradingWallet.ts) — Get trading wallet address from persisted session
|
|
221
|
+
- [`useBitcoinBalance()`](src/hooks/bitcoin/useBitcoinBalance.ts) — BTC balance for any address
|
|
222
|
+
- [`useTradingWalletBalance()`](src/hooks/bitcoin/useTradingWalletBalance.ts) — Trading wallet balance from Radfi API
|
|
223
|
+
- [`useFundTradingWallet()`](src/hooks/bitcoin/useFundTradingWallet.ts) — Fund trading wallet from personal wallet
|
|
224
|
+
- [`useRadfiWithdraw()`](src/hooks/bitcoin/useRadfiWithdraw.ts) — Withdraw from trading wallet
|
|
225
|
+
- [`useExpiredUtxos()`](src/hooks/bitcoin/useExpiredUtxos.ts) — Fetch expired UTXOs (polls every 60s)
|
|
226
|
+
- [`useRenewUtxos()`](src/hooks/bitcoin/useRenewUtxos.ts) — Renew expired UTXOs
|
|
227
|
+
|
|
228
|
+
### Partner Hooks
|
|
229
|
+
|
|
230
|
+
- [`useFetchAssetsBalances()`](src/hooks/partner/useFetchAssetsBalances.ts) — Fetch partner asset balances
|
|
231
|
+
- [`useGetAutoSwapPreferences()`](src/hooks/partner/useGetAutoSwapPreferences.ts) — Get auto-swap preferences
|
|
232
|
+
- [`useIsTokenApproved()`](src/hooks/partner/useIsTokenApproved.ts) — Check token approval
|
|
233
|
+
- [`useApproveToken()`](src/hooks/partner/useApproveToken.ts) — Approve token
|
|
234
|
+
- [`useSetSwapPreference()`](src/hooks/partner/useSetSwapPreference.ts) — Set swap preference
|
|
235
|
+
- [`useFeeClaimSwap()`](src/hooks/partner/useFeeClaimSwap.ts) — Claim partner fees via swap
|
|
236
|
+
|
|
237
|
+
### Recovery Hooks
|
|
238
|
+
|
|
239
|
+
- [`useHubAssetBalances()`](src/hooks/recovery/useHubAssetBalances.ts) — Get hub asset balances
|
|
240
|
+
- [`useWithdrawHubAsset()`](src/hooks/recovery/useWithdrawHubAsset.ts) — Withdraw hub asset
|
|
241
|
+
|
|
242
|
+
### Shared Hooks
|
|
243
|
+
|
|
244
|
+
- [`useSodaxContext()`](src/hooks/shared/useSodaxContext.ts) — Access the `Sodax` SDK instance
|
|
245
|
+
- [`useHubProvider()`](src/hooks/provider/useHubProvider.ts) — Access the hub chain (Sonic) provider
|
|
246
|
+
- [`useXBalances()`](src/hooks/shared/useXBalances.ts) — Cross-chain token balances for an address
|
|
247
|
+
- [`useDeriveUserWalletAddress()`](src/hooks/shared/useDeriveUserWalletAddress.ts) — Derive hub wallet address (CREATE3)
|
|
248
|
+
- [`useGetUserHubWalletAddress()`](src/hooks/shared/useGetUserHubWalletAddress.ts) — Derive hub wallet address (wallet router)
|
|
249
|
+
- [`useEstimateGas()`](src/hooks/shared/useEstimateGas.ts) — Estimate gas for transactions
|
|
250
|
+
- [`useStellarTrustlineCheck()`](src/hooks/shared/useStellarTrustlineCheck.ts) — Check Stellar trustline
|
|
251
|
+
- [`useRequestTrustline()`](src/hooks/shared/useRequestTrustline.ts) — Request Stellar trustline
|
|
252
|
+
|
|
253
|
+
### Backend Query Hooks
|
|
254
|
+
|
|
255
|
+
- [`useBackendIntentByTxHash()`](src/hooks/backend/useBackendIntentByTxHash.ts) — Get intent by hub tx hash (polls 1s)
|
|
256
|
+
- [`useBackendIntentByHash()`](src/hooks/backend/useBackendIntentByHash.ts) — Get intent by intent hash
|
|
257
|
+
- [`useBackendUserIntents()`](src/hooks/backend/useBackendUserIntents.ts) — All intents for a user with date filtering
|
|
258
|
+
- [`useBackendOrderbook()`](src/hooks/backend/useBackendOrderbook.ts) — Solver orderbook (cached 30s, no auto-refetch)
|
|
259
|
+
- [`useBackendMoneyMarketPosition()`](src/hooks/backend/useBackendMoneyMarketPosition.ts) — User money market position
|
|
260
|
+
- [`useBackendAllMoneyMarketAssets()`](src/hooks/backend/useBackendAllMoneyMarketAssets.ts) — All MM assets
|
|
261
|
+
- [`useBackendMoneyMarketAsset()`](src/hooks/backend/useBackendMoneyMarketAsset.ts) — Single MM asset details
|
|
262
|
+
- [`useBackendMoneyMarketAssetBorrowers()`](src/hooks/backend/useBackendMoneyMarketAssetBorrowers.ts) — Asset borrowers
|
|
263
|
+
- [`useBackendMoneyMarketAssetSuppliers()`](src/hooks/backend/useBackendMoneyMarketAssetSuppliers.ts) — Asset suppliers
|
|
264
|
+
- [`useBackendAllMoneyMarketBorrowers()`](src/hooks/backend/useBackendAllMoneyMarketBorrowers.ts) — All borrowers
|
|
265
|
+
- [`useBackendSubmitSwapTx()`](src/hooks/backend/useBackendSubmitSwapTx.ts) — Submit swap tx to backend
|
|
266
|
+
- [`useBackendSubmitSwapTxStatus()`](src/hooks/backend/useBackendSubmitSwapTxStatus.ts) — Check submitted swap status
|
|
267
|
+
|
|
268
|
+
### DEX Utils
|
|
269
|
+
|
|
270
|
+
- [`createDepositParamsProps()`](src/utils/dex-utils.ts) — Build deposit params from pool data and spoke asset info
|
|
271
|
+
- [`createWithdrawParamsProps()`](src/utils/dex-utils.ts) — Build withdraw params with optional destination info
|
|
272
|
+
- [`createSupplyLiquidityParamsProps()`](src/utils/dex-utils.ts) — Build concentrated liquidity supply params
|
|
273
|
+
- [`createDecreaseLiquidityParamsProps()`](src/utils/dex-utils.ts) — Build decrease liquidity params
|
|
458
274
|
|
|
459
275
|
## Development
|
|
460
276
|
|
|
461
277
|
```bash
|
|
462
|
-
# Install dependencies
|
|
463
|
-
pnpm
|
|
278
|
+
pnpm install # Install dependencies
|
|
279
|
+
pnpm build # Build the package (ESM + CJS)
|
|
280
|
+
pnpm dev # Watch mode
|
|
281
|
+
pnpm checkTs # Type checking
|
|
282
|
+
pnpm test # Run tests
|
|
283
|
+
pnpm pretty # Format code
|
|
284
|
+
pnpm lint # Lint code
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
## AI agent docs
|
|
464
288
|
|
|
465
|
-
|
|
466
|
-
pnpm build
|
|
289
|
+
`@sodax/dapp-kit` ships an AI-ready documentation tree at `node_modules/@sodax/dapp-kit/ai-exported/`. It's tool-neutral: any agent that can read files (Claude Code, Cursor, Aider, Copilot Chat, ChatGPT with file context, etc.) can use it without further setup.
|
|
467
290
|
|
|
468
|
-
|
|
469
|
-
pnpm dev
|
|
291
|
+
### Get started
|
|
470
292
|
|
|
471
|
-
|
|
472
|
-
pnpm checkTs
|
|
293
|
+
Point your agent at `node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md` — it routes to the rest. Three sample prompts covering the typical entry points:
|
|
473
294
|
|
|
474
|
-
|
|
475
|
-
|
|
295
|
+
```
|
|
296
|
+
> Read node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md and integrate
|
|
297
|
+
> SODAX cross-chain swaps into my React app.
|
|
298
|
+
|
|
299
|
+
> Read node_modules/@sodax/dapp-kit/ai-exported/AGENTS.md. My app uses
|
|
300
|
+
> v1 dapp-kit (useSpokeProvider, custom approve return shapes) — port to v2.
|
|
476
301
|
|
|
477
|
-
|
|
478
|
-
|
|
302
|
+
> Look up the canonical mutation hook shape in
|
|
303
|
+
> node_modules/@sodax/dapp-kit/ai-exported/integration/architecture.md.
|
|
479
304
|
```
|
|
480
305
|
|
|
306
|
+
### What's inside
|
|
307
|
+
|
|
308
|
+
```
|
|
309
|
+
ai-exported/
|
|
310
|
+
├── AGENTS.md # Tool-neutral entry point — start here
|
|
311
|
+
├── integration/ # Building NEW v2 dapp-kit code
|
|
312
|
+
│ ├── README.md, ai-rules.md # Index + DO / DO NOT / workflow for agents
|
|
313
|
+
│ ├── quickstart.md # Install + wire providers + first feature
|
|
314
|
+
│ ├── architecture.md # Hook shapes, queryKey conventions, useSafeMutation, mutateAsyncSafe
|
|
315
|
+
│ ├── features/ # 8 feature pages: swap, money-market, staking, bridge,
|
|
316
|
+
│ │ # dex, migration, bitcoin (Radfi), auxiliary-services
|
|
317
|
+
│ ├── recipes/ # 13 patterns: setup, wallet-connectivity, per-feature flows,
|
|
318
|
+
│ │ # mutation error handling, observability, invalidations
|
|
319
|
+
│ └── reference/ # 4 lookup tables: full hook index, queryKey conventions,
|
|
320
|
+
│ # public API surface, glossary
|
|
321
|
+
└── migration/ # Porting EXISTING v1 dapp-kit code to v2
|
|
322
|
+
├── README.md, ai-rules.md # Index + workflow for porting agents
|
|
323
|
+
├── checklist.md # Top-down cross-cutting checklist
|
|
324
|
+
├── breaking-changes/ # 4 cross-cutting changes: hook-signatures, result-handling,
|
|
325
|
+
│ # querykey-conventions, sdk-leakage
|
|
326
|
+
├── features/ # 8 per-feature porting playbooks
|
|
327
|
+
├── recipes.md # Codemods + adapters
|
|
328
|
+
└── reference/ # 3 reference tables: deleted hooks, renamed hooks,
|
|
329
|
+
# error-shape crosswalk
|
|
330
|
+
```
|
|
331
|
+
|
|
332
|
+
### Scope
|
|
333
|
+
|
|
334
|
+
This tree documents `@sodax/dapp-kit` (a React hooks library) only. It assumes:
|
|
335
|
+
|
|
336
|
+
- **TypeScript + React** (>=18). Examples use TSX.
|
|
337
|
+
- **Framework-agnostic**: works in any React app (Vite, Next.js client components, CRA, Remix, etc.). **No Next.js Server Components content** — dapp-kit is client-side React.
|
|
338
|
+
- **Sibling packages used in examples**: `@sodax/sdk` (peer; types and config; re-exported transparently from dapp-kit), `@sodax/wallet-sdk-react` (sibling; `useWalletProvider` is in every signed-flow example), `@tanstack/react-query` (peer).
|
|
339
|
+
- **`@sodax/types` is re-exported** through `@sodax/sdk` (which dapp-kit re-exports); consumers don't add it as a separate dependency.
|
|
340
|
+
|
|
341
|
+
The underlying Core SDK has its own ai-exported tree at `node_modules/@sodax/sdk/ai-exported/` (resolves correctly in node_modules). The dapp-kit migration tree links to it for SDK-leakage topics (chain-key terminology, `Result<T>` semantics, `SodaxError<C>`).
|
|
342
|
+
|
|
343
|
+
### Integrity guarantees
|
|
344
|
+
|
|
345
|
+
Every release passes seven CI checks against `ai-exported/`:
|
|
346
|
+
|
|
347
|
+
| Guard | What it catches |
|
|
348
|
+
|---|---|
|
|
349
|
+
| `check:ai-exported` | Each `useFoo` hook reference in markdown matches a real exported hook from `@sodax/dapp-kit` (or an upstream allowlist: React, React Query, wallet-sdk-react). |
|
|
350
|
+
| `check:ai-scope` | No accidental imports from forbidden packages (e.g. `@sodax/wallet-sdk-core` for Node-only flows; `@sodax/types` directly). |
|
|
351
|
+
| `check:ai-links` | Every relative link between markdown files resolves (including cross-package links into `../../../sdk/ai-exported/`). |
|
|
352
|
+
| `check:ai-imports` | Every `import … from '@sodax/dapp-kit'` example in the docs typechecks against the package source. |
|
|
353
|
+
| `check:ai-snippets` | Every fenced ````ts`/````tsx` block is typechecked AS-IS against source (opt-out via `// @ai-snippets-skip` for genuinely illustrative blocks). Catches call-shape drift like wrong `useQuote({ params: <Request> })` vs canonical `useQuote({ params: { payload: <Request> } })`. |
|
|
354
|
+
| `check:ai-keys` | Every `queryKey:` / `mutationKey:` literal in docs (both `kind: [...]` declarations and backticked-array table cells) matches a real source key prefix. Catches drift like `['staking', 'stakingInfo']` in docs when source uses `['staking', 'info']`. |
|
|
355
|
+
| `check:ai-consistency` | Polling-interval claims in docs (e.g. "polls 3s", "auto-refresh every 2s") match the actual `refetchInterval` value in source. Catches drift like docs claiming 1s when source is 3000ms. |
|
|
356
|
+
|
|
357
|
+
If you're contributing to this repo, run them with `pnpm -C packages/dapp-kit run check:ai-exported` (or `:scope`, `:links`, `:imports`, `:snippets`, `:keys`, `:consistency`).
|
|
358
|
+
|
|
481
359
|
## License
|
|
482
360
|
|
|
483
361
|
[MIT](LICENSE)
|
|
484
362
|
|
|
485
363
|
## Support
|
|
486
364
|
|
|
487
|
-
- [GitHub Issues](https://github.com/icon-project/sodax-
|
|
365
|
+
- [GitHub Issues](https://github.com/icon-project/sodax-sdks/issues)
|
|
488
366
|
- [Discord Community](https://discord.gg/sodax-formerly-icon-880651922682560582)
|