@sodax/dapp-kit 1.5.7-beta → 2.0.0-rc.10
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 +247 -423
- package/dist/index.d.ts +1027 -2051
- package/dist/index.mjs +1580 -1533
- package/package.json +34 -12
- 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 +13 -82
- 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 +21 -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 -2574
- package/dist/index.js.map +0 -1
- package/dist/index.mjs.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';
|
|
39
|
+
|
|
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
|
+
};
|
|
97
51
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const queryClient = new QueryClient();
|
|
107
|
-
|
|
108
|
-
const rpcConfig: RpcConfig = {
|
|
109
|
-
// EVM chains
|
|
110
|
-
sonic: 'https://rpc.soniclabs.com',
|
|
111
|
-
'0xa86a.avax': 'https://api.avax.network/ext/bc/C/rpc',
|
|
112
|
-
'0xa4b1.arbitrum': 'https://arb1.arbitrum.io/rpc',
|
|
113
|
-
'0x2105.base': 'https://mainnet.base.org',
|
|
114
|
-
'0x38.bsc': 'https://bsc-dataseed1.binance.org',
|
|
115
|
-
'0xa.optimism': 'https://mainnet.optimism.io',
|
|
116
|
-
'0x89.polygon': 'https://polygon-rpc.com',
|
|
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',
|
|
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,242 @@ 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
|
-
- Node.js >=
|
|
386
|
-
- React >=
|
|
120
|
+
- Node.js >= 20.12.0
|
|
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
|
+
```
|
|
464
286
|
|
|
465
|
-
|
|
466
|
-
pnpm build
|
|
287
|
+
## AI agent docs
|
|
467
288
|
|
|
468
|
-
|
|
469
|
-
pnpm dev
|
|
289
|
+
AI-readable docs for `@sodax/dapp-kit` (and the other `@sodax/*` packages) are shipped via [`@sodax/skills`](https://github.com/icon-project/sodax-sdks/tree/main/packages/skills) — a separate npm package bundling Claude-Code SKILL.md files and a long-form knowledge tree.
|
|
470
290
|
|
|
471
|
-
|
|
472
|
-
pnpm checkTs
|
|
291
|
+
**Recommended: [`skills` CLI](https://github.com/vercel-labs/skills)** — from your project root:
|
|
473
292
|
|
|
474
|
-
|
|
475
|
-
|
|
293
|
+
```bash
|
|
294
|
+
npx skills@latest add icon-project/sodax-sdks/packages/skills
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**npm + `AGENTS.md` pointer** (fallback for web chats, or when you prefer a devDependency over the CLI):
|
|
476
298
|
|
|
477
|
-
|
|
478
|
-
pnpm
|
|
299
|
+
```bash
|
|
300
|
+
pnpm add -D @sodax/skills
|
|
479
301
|
```
|
|
480
302
|
|
|
303
|
+
Then point your agent at `node_modules/@sodax/skills/AGENTS.md`. See [docs/ai-integration-guide.md](https://github.com/icon-project/sodax-sdks/blob/main/docs/ai-integration-guide.md) for all install modes and per-tool wiring.
|
|
304
|
+
|
|
481
305
|
## License
|
|
482
306
|
|
|
483
307
|
[MIT](LICENSE)
|
|
484
308
|
|
|
485
309
|
## Support
|
|
486
310
|
|
|
487
|
-
- [GitHub Issues](https://github.com/icon-project/sodax-
|
|
311
|
+
- [GitHub Issues](https://github.com/icon-project/sodax-sdks/issues)
|
|
488
312
|
- [Discord Community](https://discord.gg/sodax-formerly-icon-880651922682560582)
|