@sodax/dapp-kit 2.2.0-rc.2 → 2.2.0-rc.4
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/dist/index.d.ts +505 -2
- package/dist/index.mjs +608 -3
- package/package.json +2 -2
- package/src/hooks/_apiKeyWire.test.ts +383 -17
- package/src/hooks/_mutationContract.test.ts +7 -0
- package/src/hooks/index.ts +1 -0
- package/src/hooks/leverageYieldApi/index.ts +55 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAllowance.ts +50 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApprove.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.test.ts +176 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApproveAndBroadcast.ts +83 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiApr.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiAsset.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCancelIntent.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateDepositIntent.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiCreateWithdrawIntent.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDeadline.ts +38 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiDepositQuote.ts +57 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEffectiveApr.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiEstimateGas.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiFilledIntent.ts +40 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntent.ts +40 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentExtraData.ts +42 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentHash.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiIntentPacket.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiLsdApr.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiMaxWithdraw.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPartnerFee.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPosition.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewDeposit.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewRedeem.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiPreviewWithdraw.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiShareBalance.ts +43 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSolverFee.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiStatus.ts +48 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitIntent.ts +36 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTx.ts +37 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiSubmitTxStatus.ts +60 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiTotalAssets.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVault.ts +41 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiVaults.ts +36 -0
- package/src/hooks/leverageYieldApi/useLeverageYieldApiWithdrawQuote.ts +56 -0
- package/src/hooks/swapsApi/useSwapsApiApproveAndBroadcast.test.ts +5 -1
- package/src/utils/approvalPlan.ts +4 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { IntentStateV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiFilledIntentParams = ReadHookParams<
|
|
9
|
+
IntentStateV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
txHash: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to get the on-chain fill state for an intent by its hub-chain tx hash via the leverage-yield API — `sodax.api.leverageYield.getFilledIntent`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { data } = useLeverageYieldApiFilledIntent({ params: { txHash: '0x123...' } });
|
|
21
|
+
*/
|
|
22
|
+
export const useLeverageYieldApiFilledIntent = ({
|
|
23
|
+
params,
|
|
24
|
+
queryOptions,
|
|
25
|
+
}: UseLeverageYieldApiFilledIntentParams = {}): UseQueryResult<IntentStateV2 | undefined, Error> => {
|
|
26
|
+
const { sodax } = useSodaxContext();
|
|
27
|
+
const txHash = params?.txHash;
|
|
28
|
+
const apiConfig = params?.apiConfig;
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['leverageYieldApi', 'filledIntent', txHash],
|
|
32
|
+
queryFn: async (): Promise<IntentStateV2 | undefined> => {
|
|
33
|
+
if (!txHash) return undefined;
|
|
34
|
+
return unwrapResult(await sodax.api.leverageYield.getFilledIntent(txHash, apiConfig));
|
|
35
|
+
},
|
|
36
|
+
enabled: !!txHash && txHash.length > 0,
|
|
37
|
+
retry: retryUnlessAuthFailure,
|
|
38
|
+
...queryOptions,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { GetIntentResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiIntentParams = ReadHookParams<
|
|
9
|
+
GetIntentResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
txHash: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to look up an Intent struct by its hub-chain creation tx hash via the leverage-yield API — `sodax.api.leverageYield.getIntent`.
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* const { data } = useLeverageYieldApiIntent({ params: { txHash: '0x123...' } });
|
|
21
|
+
*/
|
|
22
|
+
export const useLeverageYieldApiIntent = ({
|
|
23
|
+
params,
|
|
24
|
+
queryOptions,
|
|
25
|
+
}: UseLeverageYieldApiIntentParams = {}): UseQueryResult<GetIntentResponseV2 | undefined, Error> => {
|
|
26
|
+
const { sodax } = useSodaxContext();
|
|
27
|
+
const txHash = params?.txHash;
|
|
28
|
+
const apiConfig = params?.apiConfig;
|
|
29
|
+
|
|
30
|
+
return useQuery({
|
|
31
|
+
queryKey: ['leverageYieldApi', 'intent', txHash],
|
|
32
|
+
queryFn: async (): Promise<GetIntentResponseV2 | undefined> => {
|
|
33
|
+
if (!txHash) return undefined;
|
|
34
|
+
return unwrapResult(await sodax.api.leverageYield.getIntent(txHash, apiConfig));
|
|
35
|
+
},
|
|
36
|
+
enabled: !!txHash && txHash.length > 0,
|
|
37
|
+
retry: retryUnlessAuthFailure,
|
|
38
|
+
...queryOptions,
|
|
39
|
+
});
|
|
40
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { IntentExtraDataRequestV2, IntentExtraDataResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiIntentExtraDataParams = ReadHookParams<
|
|
9
|
+
IntentExtraDataResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
body: IntentExtraDataRequestV2 | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to recover the relay extra data needed by `/leverage-yield/intents/submit` via the
|
|
18
|
+
* leverage-yield API — `sodax.api.leverageYield.getIntentSubmitTxExtraData`. Provide EITHER `txHash`
|
|
19
|
+
* OR `intent` in the body.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiIntentExtraData({ params: { body: { txHash: '0x...' } } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiIntentExtraData = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiIntentExtraDataParams = {}): UseQueryResult<IntentExtraDataResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const body = params?.body;
|
|
30
|
+
const apiConfig = params?.apiConfig;
|
|
31
|
+
|
|
32
|
+
return useQuery({
|
|
33
|
+
queryKey: ['leverageYieldApi', 'intentExtraData', body?.txHash ?? body?.intent?.intentId?.toString()],
|
|
34
|
+
queryFn: async (): Promise<IntentExtraDataResponseV2 | undefined> => {
|
|
35
|
+
if (!body || (!body.txHash && !body.intent)) return undefined;
|
|
36
|
+
return unwrapResult(await sodax.api.leverageYield.getIntentSubmitTxExtraData(body, apiConfig));
|
|
37
|
+
},
|
|
38
|
+
enabled: !!body && (!!body.txHash || !!body.intent),
|
|
39
|
+
retry: retryUnlessAuthFailure,
|
|
40
|
+
...queryOptions,
|
|
41
|
+
});
|
|
42
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { IntentHashResponseV2, IntentRequestV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiIntentHashParams = ReadHookParams<
|
|
9
|
+
IntentHashResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
intent: IntentRequestV2 | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to compute the keccak256 hash of an Intent struct via the leverage-yield API —
|
|
18
|
+
* `sodax.api.leverageYield.getIntentHash`. Returns `{ hash }`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiIntentHash({ params: { intent } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiIntentHash = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiIntentHashParams = {}): UseQueryResult<IntentHashResponseV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const intent = params?.intent;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'intentHash', intent?.intentId?.toString()],
|
|
33
|
+
queryFn: async (): Promise<IntentHashResponseV2 | undefined> => {
|
|
34
|
+
if (!intent) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getIntentHash({ intent }, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!intent,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { IntentPacketRequestV2, IntentPacketResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiIntentPacketParams = ReadHookParams<
|
|
9
|
+
IntentPacketResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
body: IntentPacketRequestV2 | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to long-poll the relayer until the fill packet lands on the destination chain via the
|
|
18
|
+
* leverage-yield API — `sodax.api.leverageYield.getSolvedIntentPacket`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiIntentPacket({ params: { body: { chainId: 'sonic', fillTxHash: '0x...' } } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiIntentPacket = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiIntentPacketParams = {}): UseQueryResult<IntentPacketResponseV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const body = params?.body;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'intentPacket', body?.chainId, body?.fillTxHash],
|
|
33
|
+
queryFn: async (): Promise<IntentPacketResponseV2 | undefined> => {
|
|
34
|
+
if (!body) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getSolvedIntentPacket(body, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!body,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { LeverageYieldLsdAprV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiLsdAprParams = ReadHookParams<
|
|
9
|
+
LeverageYieldLsdAprV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to fetch the off-chain LSD staking-APR snapshot for a leverage-yield vault via the leverage-yield API —
|
|
18
|
+
* `sodax.api.leverageYield.getLsdApr`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiLsdApr({ params: { vault: '0x...' } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiLsdApr = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiLsdAprParams = {}): UseQueryResult<LeverageYieldLsdAprV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const vault = params?.vault;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'lsdApr', vault],
|
|
33
|
+
queryFn: async (): Promise<LeverageYieldLsdAprV2 | undefined> => {
|
|
34
|
+
if (!vault) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getLsdApr({ vault }, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!vault && vault.length > 0,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { MaxWithdrawResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiMaxWithdrawParams = ReadHookParams<
|
|
9
|
+
MaxWithdrawResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
owner: string | undefined;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to get the maximum assets an owner can withdraw (ERC-4626 maxWithdraw) via the leverage-yield API —
|
|
19
|
+
* `sodax.api.leverageYield.getMaxWithdraw`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiMaxWithdraw({ params: { vault: '0x...', owner: '1000000000000000000' } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiMaxWithdraw = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiMaxWithdrawParams = {}): UseQueryResult<MaxWithdrawResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const vault = params?.vault;
|
|
30
|
+
const owner = params?.owner;
|
|
31
|
+
const apiConfig = params?.apiConfig;
|
|
32
|
+
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['leverageYieldApi', 'maxWithdraw', vault, owner],
|
|
35
|
+
queryFn: async (): Promise<MaxWithdrawResponseV2 | undefined> => {
|
|
36
|
+
if (!vault || owner === undefined) return undefined;
|
|
37
|
+
return unwrapResult(await sodax.api.leverageYield.getMaxWithdraw({ vault, owner }, apiConfig));
|
|
38
|
+
},
|
|
39
|
+
enabled: !!vault && vault.length > 0 && owner !== undefined,
|
|
40
|
+
retry: retryUnlessAuthFailure,
|
|
41
|
+
...queryOptions,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { FeeResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiPartnerFeeParams = ReadHookParams<
|
|
9
|
+
FeeResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
amount: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to compute the partner fee for a given input amount via the leverage-yield API — `sodax.api.leverageYield.getPartnerFee`.
|
|
18
|
+
* Returns `{ fee }` (decimal string).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiPartnerFee({ params: { amount: '1000000' } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiPartnerFee = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiPartnerFeeParams = {}): UseQueryResult<FeeResponseV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const amount = params?.amount;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'partnerFee', amount],
|
|
33
|
+
queryFn: async (): Promise<FeeResponseV2 | undefined> => {
|
|
34
|
+
if (!amount) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getPartnerFee({ amount }, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!amount && amount.length > 0,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { LeverageYieldPositionV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiPositionParams = ReadHookParams<
|
|
9
|
+
LeverageYieldPositionV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to fetch a leveraged-position snapshot for a leverage-yield vault via the leverage-yield API —
|
|
18
|
+
* `sodax.api.leverageYield.getPosition`.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiPosition({ params: { vault: '0x...' } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiPosition = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiPositionParams = {}): UseQueryResult<LeverageYieldPositionV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const vault = params?.vault;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'position', vault],
|
|
33
|
+
queryFn: async (): Promise<LeverageYieldPositionV2 | undefined> => {
|
|
34
|
+
if (!vault) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getPosition({ vault }, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!vault && vault.length > 0,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { PreviewDepositResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiPreviewDepositParams = ReadHookParams<
|
|
9
|
+
PreviewDepositResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
assets: string | undefined;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to preview the shares minted for depositing `assets` (ERC-4626 previewDeposit) via the leverage-yield API —
|
|
19
|
+
* `sodax.api.leverageYield.previewDeposit`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiPreviewDeposit({ params: { vault: '0x...', assets: '1000000000000000000' } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiPreviewDeposit = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiPreviewDepositParams = {}): UseQueryResult<PreviewDepositResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const vault = params?.vault;
|
|
30
|
+
const assets = params?.assets;
|
|
31
|
+
const apiConfig = params?.apiConfig;
|
|
32
|
+
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['leverageYieldApi', 'previewDeposit', vault, assets],
|
|
35
|
+
queryFn: async (): Promise<PreviewDepositResponseV2 | undefined> => {
|
|
36
|
+
if (!vault || assets === undefined) return undefined;
|
|
37
|
+
return unwrapResult(await sodax.api.leverageYield.previewDeposit({ vault, assets }, apiConfig));
|
|
38
|
+
},
|
|
39
|
+
enabled: !!vault && vault.length > 0 && assets !== undefined,
|
|
40
|
+
retry: retryUnlessAuthFailure,
|
|
41
|
+
...queryOptions,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { PreviewRedeemResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiPreviewRedeemParams = ReadHookParams<
|
|
9
|
+
PreviewRedeemResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
shares: string | undefined;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to preview the assets returned for redeeming `shares` (ERC-4626 previewRedeem) via the leverage-yield API —
|
|
19
|
+
* `sodax.api.leverageYield.previewRedeem`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiPreviewRedeem({ params: { vault: '0x...', shares: '1000000000000000000' } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiPreviewRedeem = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiPreviewRedeemParams = {}): UseQueryResult<PreviewRedeemResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const vault = params?.vault;
|
|
30
|
+
const shares = params?.shares;
|
|
31
|
+
const apiConfig = params?.apiConfig;
|
|
32
|
+
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['leverageYieldApi', 'previewRedeem', vault, shares],
|
|
35
|
+
queryFn: async (): Promise<PreviewRedeemResponseV2 | undefined> => {
|
|
36
|
+
if (!vault || shares === undefined) return undefined;
|
|
37
|
+
return unwrapResult(await sodax.api.leverageYield.previewRedeem({ vault, shares }, apiConfig));
|
|
38
|
+
},
|
|
39
|
+
enabled: !!vault && vault.length > 0 && shares !== undefined,
|
|
40
|
+
retry: retryUnlessAuthFailure,
|
|
41
|
+
...queryOptions,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { PreviewWithdrawResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiPreviewWithdrawParams = ReadHookParams<
|
|
9
|
+
PreviewWithdrawResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
assets: string | undefined;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to preview the shares burned to withdraw `assets` (ERC-4626 previewWithdraw) via the leverage-yield API —
|
|
19
|
+
* `sodax.api.leverageYield.previewWithdraw`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiPreviewWithdraw({ params: { vault: '0x...', assets: '1000000000000000000' } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiPreviewWithdraw = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiPreviewWithdrawParams = {}): UseQueryResult<PreviewWithdrawResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const vault = params?.vault;
|
|
30
|
+
const assets = params?.assets;
|
|
31
|
+
const apiConfig = params?.apiConfig;
|
|
32
|
+
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['leverageYieldApi', 'previewWithdraw', vault, assets],
|
|
35
|
+
queryFn: async (): Promise<PreviewWithdrawResponseV2 | undefined> => {
|
|
36
|
+
if (!vault || assets === undefined) return undefined;
|
|
37
|
+
return unwrapResult(await sodax.api.leverageYield.previewWithdraw({ vault, assets }, apiConfig));
|
|
38
|
+
},
|
|
39
|
+
enabled: !!vault && vault.length > 0 && assets !== undefined,
|
|
40
|
+
retry: retryUnlessAuthFailure,
|
|
41
|
+
...queryOptions,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { ShareBalanceResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiShareBalanceParams = ReadHookParams<
|
|
9
|
+
ShareBalanceResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
vault: string | undefined;
|
|
12
|
+
owner: string | undefined;
|
|
13
|
+
apiConfig?: RequestOverrideConfig;
|
|
14
|
+
}
|
|
15
|
+
>;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* React hook to get an owner's vault share (lsoda*) balance via the leverage-yield API —
|
|
19
|
+
* `sodax.api.leverageYield.getShareBalance`.
|
|
20
|
+
*
|
|
21
|
+
* @example
|
|
22
|
+
* const { data } = useLeverageYieldApiShareBalance({ params: { vault: '0x...', owner: '1000000000000000000' } });
|
|
23
|
+
*/
|
|
24
|
+
export const useLeverageYieldApiShareBalance = ({
|
|
25
|
+
params,
|
|
26
|
+
queryOptions,
|
|
27
|
+
}: UseLeverageYieldApiShareBalanceParams = {}): UseQueryResult<ShareBalanceResponseV2 | undefined, Error> => {
|
|
28
|
+
const { sodax } = useSodaxContext();
|
|
29
|
+
const vault = params?.vault;
|
|
30
|
+
const owner = params?.owner;
|
|
31
|
+
const apiConfig = params?.apiConfig;
|
|
32
|
+
|
|
33
|
+
return useQuery({
|
|
34
|
+
queryKey: ['leverageYieldApi', 'shareBalance', vault, owner],
|
|
35
|
+
queryFn: async (): Promise<ShareBalanceResponseV2 | undefined> => {
|
|
36
|
+
if (!vault || owner === undefined) return undefined;
|
|
37
|
+
return unwrapResult(await sodax.api.leverageYield.getShareBalance({ vault, owner }, apiConfig));
|
|
38
|
+
},
|
|
39
|
+
enabled: !!vault && vault.length > 0 && owner !== undefined,
|
|
40
|
+
retry: retryUnlessAuthFailure,
|
|
41
|
+
...queryOptions,
|
|
42
|
+
});
|
|
43
|
+
};
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { FeeResponseV2, RequestOverrideConfig } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
|
|
8
|
+
export type UseLeverageYieldApiSolverFeeParams = ReadHookParams<
|
|
9
|
+
FeeResponseV2 | undefined,
|
|
10
|
+
{
|
|
11
|
+
amount: string | undefined;
|
|
12
|
+
apiConfig?: RequestOverrideConfig;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* React hook to compute the protocol (solver) fee for a given input amount via the leverage-yield API — `sodax.api.leverageYield.getSolverFee`.
|
|
18
|
+
* Returns `{ fee }` (decimal string).
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const { data } = useLeverageYieldApiSolverFee({ params: { amount: '1000000' } });
|
|
22
|
+
*/
|
|
23
|
+
export const useLeverageYieldApiSolverFee = ({
|
|
24
|
+
params,
|
|
25
|
+
queryOptions,
|
|
26
|
+
}: UseLeverageYieldApiSolverFeeParams = {}): UseQueryResult<FeeResponseV2 | undefined, Error> => {
|
|
27
|
+
const { sodax } = useSodaxContext();
|
|
28
|
+
const amount = params?.amount;
|
|
29
|
+
const apiConfig = params?.apiConfig;
|
|
30
|
+
|
|
31
|
+
return useQuery({
|
|
32
|
+
queryKey: ['leverageYieldApi', 'solverFee', amount],
|
|
33
|
+
queryFn: async (): Promise<FeeResponseV2 | undefined> => {
|
|
34
|
+
if (!amount) return undefined;
|
|
35
|
+
return unwrapResult(await sodax.api.leverageYield.getSolverFee({ amount }, apiConfig));
|
|
36
|
+
},
|
|
37
|
+
enabled: !!amount && amount.length > 0,
|
|
38
|
+
retry: retryUnlessAuthFailure,
|
|
39
|
+
...queryOptions,
|
|
40
|
+
});
|
|
41
|
+
};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { useQuery, type UseQueryResult } from '@tanstack/react-query';
|
|
2
|
+
import type { RequestOverrideConfig, StatusResponseV2 } from '@sodax/sdk';
|
|
3
|
+
import { useSodaxContext } from '../shared/useSodaxContext.js';
|
|
4
|
+
import { retryUnlessAuthFailure } from '../shared/retryUnlessAuthFailure.js';
|
|
5
|
+
import { unwrapResult } from '../shared/unwrapResult.js';
|
|
6
|
+
import type { ReadHookParams } from '../shared/types.js';
|
|
7
|
+
// Leverage-yield intents share the solver status codes with swaps, so the terminal-status predicate
|
|
8
|
+
// is reused rather than duplicated.
|
|
9
|
+
import { isTerminalSwapIntentStatus } from '../swapsApi/isTerminalSwapIntentStatus.js';
|
|
10
|
+
|
|
11
|
+
export type UseLeverageYieldApiStatusParams = ReadHookParams<
|
|
12
|
+
StatusResponseV2 | undefined,
|
|
13
|
+
{
|
|
14
|
+
intentTxHash: string | undefined;
|
|
15
|
+
apiConfig?: RequestOverrideConfig;
|
|
16
|
+
}
|
|
17
|
+
>;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* React hook for polling the solver intent status by hub-chain intent tx hash via the leverage-yield
|
|
21
|
+
* API — `sodax.api.leverageYield.getStatus`. Returns `{ status, fillTxHash? }`.
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const { data } = useLeverageYieldApiStatus({ params: { intentTxHash: '0x123...' } });
|
|
25
|
+
*
|
|
26
|
+
* @remarks
|
|
27
|
+
* - Default refetch interval is 1 second; stops once `status` is `3` (SOLVED) or `4` (FAILED).
|
|
28
|
+
*/
|
|
29
|
+
export const useLeverageYieldApiStatus = ({
|
|
30
|
+
params,
|
|
31
|
+
queryOptions,
|
|
32
|
+
}: UseLeverageYieldApiStatusParams = {}): UseQueryResult<StatusResponseV2 | undefined, Error> => {
|
|
33
|
+
const { sodax } = useSodaxContext();
|
|
34
|
+
const intentTxHash = params?.intentTxHash;
|
|
35
|
+
const apiConfig = params?.apiConfig;
|
|
36
|
+
|
|
37
|
+
return useQuery({
|
|
38
|
+
queryKey: ['leverageYieldApi', 'status', intentTxHash],
|
|
39
|
+
queryFn: async (): Promise<StatusResponseV2 | undefined> => {
|
|
40
|
+
if (!intentTxHash) return undefined;
|
|
41
|
+
return unwrapResult(await sodax.api.leverageYield.getStatus({ intentTxHash }, apiConfig));
|
|
42
|
+
},
|
|
43
|
+
enabled: !!intentTxHash && intentTxHash.length > 0,
|
|
44
|
+
retry: retryUnlessAuthFailure,
|
|
45
|
+
refetchInterval: query => (isTerminalSwapIntentStatus(query.state.data?.status) ? false : 1000),
|
|
46
|
+
...queryOptions,
|
|
47
|
+
});
|
|
48
|
+
};
|