@zkp2p/sdk 0.10.0-rc.6 → 0.10.0

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/react.d.mts CHANGED
@@ -1,5 +1,5 @@
1
- import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a2 as SignalIntentMethodParams, bI as PreparedTransaction, bO as TakerStake, E as GetTakerStakeRequest, F as GetTakerStakeResponse, bR as TakerCapacity, H as GetTakerCapacityRequest, J as GetTakerCapacityResponse, a3 as FulfillIntentMethodParams, dc as SendTransactionFn, dd as SendBatchFn, da as DelegationDepositTarget, db as BatchResult } from './vaultUtils-B2FVQeaS.mjs';
2
- export { d8 as DelegationRoute, d9 as DelegationState, de as VAULT_ZERO_ADDRESS, d2 as ZERO_RATE_MANAGER_ID, df as asErrorMessage, dg as assertDelegationMethodSupport, d7 as classifyDelegationState, d6 as getDelegationRoute, d3 as isZeroRateManagerId, d4 as normalizeRateManagerId, d5 as normalizeRegistry } from './vaultUtils-B2FVQeaS.mjs';
1
+ import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a1 as SignalIntentMethodParams, bK as PreparedTransaction, bN as TakerTier, E as GetTakerTierRequest, F as GetTakerTierResponse, a2 as FulfillIntentMethodParams, d5 as SendTransactionFn, d6 as SendBatchFn, d3 as DelegationDepositTarget, d4 as BatchResult, aa as IntentGuardianErrorCode, a6 as IntentGuardianPolicy, a7 as IntentGuardianQuote } from './vaultUtils-DeUFIx3l.mjs';
2
+ export { d1 as DelegationRoute, d2 as DelegationState, dl as VAULT_ZERO_ADDRESS, cX as ZERO_RATE_MANAGER_ID, dm as asErrorMessage, dn as assertDelegationMethodSupport, d0 as classifyDelegationState, c$ as getDelegationRoute, cY as isZeroRateManagerId, cZ as normalizeRateManagerId, c_ as normalizeRegistry } from './vaultUtils-DeUFIx3l.mjs';
3
3
  import { Hash, Address, Hex } from 'viem';
4
4
  import '@zkp2p/indexer-schema';
5
5
  import 'abitype';
@@ -60,45 +60,26 @@ declare function useSignalIntent({ client, onSuccess, onError }: UseSignalIntent
60
60
  prepared: PreparedTransaction | null;
61
61
  };
62
62
 
63
- interface UseGetTakerStakeOptions {
63
+ interface UseGetTakerTierOptions {
64
64
  client: Zkp2pClient | null;
65
65
  owner?: string | null;
66
66
  chainId?: number | null;
67
67
  autoFetch?: boolean;
68
- onSuccess?: (stake: TakerStake) => void;
68
+ onSuccess?: (tier: TakerTier) => void;
69
69
  onError?: (error: Error) => void;
70
70
  }
71
- /**
72
- * Fetches the stake portfolio backing a taker: balances, reservation
73
- * aggregates, delegation, and exit state.
74
- */
75
- declare function useGetTakerStake({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerStakeOptions): {
76
- getTakerStake: (params?: GetTakerStakeRequest) => Promise<GetTakerStakeResponse | null>;
77
- takerStake: TakerStake | null;
71
+ declare function useGetTakerTier({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerTierOptions): {
72
+ getTakerTier: (params?: GetTakerTierRequest) => Promise<GetTakerTierResponse | null>;
73
+ takerTier: TakerTier | null;
78
74
  isLoading: boolean;
79
75
  error: Error | null;
80
76
  };
81
-
82
- interface UseGetTakerCapacityOptions {
83
- client: Zkp2pClient | null;
84
- owner?: string | null;
85
- chainId?: number | null;
86
- autoFetch?: boolean;
87
- onSuccess?: (capacity: TakerCapacity) => void;
88
- onError?: (error: Error) => void;
89
- }
90
- /**
91
- * Fetches per-platform bonded taking capacity, free takes, and operational
92
- * gates for a taker's shared stake portfolio. Platform capacities are
93
- * alternative views of one shared balance — never sum them. Capacity can
94
- * change whenever any authorized relayer uses the shared stake, so refetch
95
- * immediately before signaling an intent; the contract stays authoritative.
96
- */
97
- declare function useGetTakerCapacity({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerCapacityOptions): {
98
- getTakerCapacity: (params?: GetTakerCapacityRequest) => Promise<GetTakerCapacityResponse | null>;
99
- takerCapacity: TakerCapacity | null;
100
- isLoading: boolean;
101
- error: Error | null;
77
+ declare function getNextTierCap(currentTier: string | undefined): string | null;
78
+ declare function getTierDisplayInfo(tier: TakerTier | undefined): {
79
+ tierLabel: string;
80
+ capDisplay: string;
81
+ isNewUser: boolean;
82
+ showScore: boolean;
102
83
  };
103
84
 
104
85
  interface UseFulfillIntentOptions {
@@ -338,6 +319,38 @@ declare function useSetVaultFee({ client, onSuccess, onError }: UseSetVaultFeeOp
338
319
  prepared: PreparedTransaction | null;
339
320
  };
340
321
 
322
+ interface UseExtendIntentLifetimeOptions {
323
+ client: Zkp2pClient | null;
324
+ onSuccess?: (hash: Hash) => void;
325
+ onError?: (error: Error, code: IntentGuardianErrorCode) => void;
326
+ }
327
+ /**
328
+ * Prepaid intent extension through the standalone IntentGuardian.
329
+ *
330
+ * The fee is owner-governed and can change at any time, so this hook never
331
+ * caches it: `refreshPolicy` and `quote` both read live state, and callers
332
+ * should re-quote immediately before signing and derive `maxCost` from that
333
+ * fresh result.
334
+ */
335
+ declare function useExtendIntentLifetime({ client, onSuccess, onError, }: UseExtendIntentLifetimeOptions): {
336
+ extendIntentLifetime: (params: Parameters<Zkp2pClient["extendIntentLifetime"]>[0]) => Promise<`0x${string}` | null>;
337
+ prepareExtendIntentLifetime: (params: Parameters<Zkp2pClient["extendIntentLifetime"]>[0]) => Promise<PreparedTransaction | null>;
338
+ refreshPolicy: () => Promise<IntentGuardianPolicy | null>;
339
+ refreshQuote: (params: {
340
+ intentAmount: bigint;
341
+ additionalTime: bigint;
342
+ }) => Promise<IntentGuardianQuote | null>;
343
+ policy: IntentGuardianPolicy | null;
344
+ quote: IntentGuardianQuote | null;
345
+ isLoading: boolean;
346
+ error: Error | null;
347
+ errorCode: IntentGuardianErrorCode | null;
348
+ txHash: `0x${string}` | null;
349
+ prepared: PreparedTransaction | null;
350
+ /** False where no guardian is deployed; hide the extension action entirely. */
351
+ isAvailable: boolean;
352
+ };
353
+
341
354
  interface UseSetVaultMinRateOptions {
342
355
  client: Zkp2pClient | null;
343
356
  onSuccess?: (hash: Hash) => void;
@@ -450,4 +463,4 @@ declare function usePruneExpiredIntents({ client, onSuccess, onError }: UsePrune
450
463
  txHash: `0x${string}` | null;
451
464
  };
452
465
 
453
- export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseFulfillIntentOptions, type UseGetTakerCapacityOptions, type UseGetTakerStakeOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerCapacity, useGetTakerStake, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
466
+ export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseExtendIntentLifetimeOptions, type UseFulfillIntentOptions, type UseGetTakerTierOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, getNextTierCap, getTierDisplayInfo, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useExtendIntentLifetime, useFulfillIntent, useGetTakerTier, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
package/dist/react.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a2 as SignalIntentMethodParams, bI as PreparedTransaction, bO as TakerStake, E as GetTakerStakeRequest, F as GetTakerStakeResponse, bR as TakerCapacity, H as GetTakerCapacityRequest, J as GetTakerCapacityResponse, a3 as FulfillIntentMethodParams, dc as SendTransactionFn, dd as SendBatchFn, da as DelegationDepositTarget, db as BatchResult } from './vaultUtils-B2FVQeaS.js';
2
- export { d8 as DelegationRoute, d9 as DelegationState, de as VAULT_ZERO_ADDRESS, d2 as ZERO_RATE_MANAGER_ID, df as asErrorMessage, dg as assertDelegationMethodSupport, d7 as classifyDelegationState, d6 as getDelegationRoute, d3 as isZeroRateManagerId, d4 as normalizeRateManagerId, d5 as normalizeRegistry } from './vaultUtils-B2FVQeaS.js';
1
+ import { Z as Zkp2pClient, P as PostDepositDetailsRequest, a1 as SignalIntentMethodParams, bK as PreparedTransaction, bN as TakerTier, E as GetTakerTierRequest, F as GetTakerTierResponse, a2 as FulfillIntentMethodParams, d5 as SendTransactionFn, d6 as SendBatchFn, d3 as DelegationDepositTarget, d4 as BatchResult, aa as IntentGuardianErrorCode, a6 as IntentGuardianPolicy, a7 as IntentGuardianQuote } from './vaultUtils-DeUFIx3l.js';
2
+ export { d1 as DelegationRoute, d2 as DelegationState, dl as VAULT_ZERO_ADDRESS, cX as ZERO_RATE_MANAGER_ID, dm as asErrorMessage, dn as assertDelegationMethodSupport, d0 as classifyDelegationState, c$ as getDelegationRoute, cY as isZeroRateManagerId, cZ as normalizeRateManagerId, c_ as normalizeRegistry } from './vaultUtils-DeUFIx3l.js';
3
3
  import { Hash, Address, Hex } from 'viem';
4
4
  import '@zkp2p/indexer-schema';
5
5
  import 'abitype';
@@ -60,45 +60,26 @@ declare function useSignalIntent({ client, onSuccess, onError }: UseSignalIntent
60
60
  prepared: PreparedTransaction | null;
61
61
  };
62
62
 
63
- interface UseGetTakerStakeOptions {
63
+ interface UseGetTakerTierOptions {
64
64
  client: Zkp2pClient | null;
65
65
  owner?: string | null;
66
66
  chainId?: number | null;
67
67
  autoFetch?: boolean;
68
- onSuccess?: (stake: TakerStake) => void;
68
+ onSuccess?: (tier: TakerTier) => void;
69
69
  onError?: (error: Error) => void;
70
70
  }
71
- /**
72
- * Fetches the stake portfolio backing a taker: balances, reservation
73
- * aggregates, delegation, and exit state.
74
- */
75
- declare function useGetTakerStake({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerStakeOptions): {
76
- getTakerStake: (params?: GetTakerStakeRequest) => Promise<GetTakerStakeResponse | null>;
77
- takerStake: TakerStake | null;
71
+ declare function useGetTakerTier({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerTierOptions): {
72
+ getTakerTier: (params?: GetTakerTierRequest) => Promise<GetTakerTierResponse | null>;
73
+ takerTier: TakerTier | null;
78
74
  isLoading: boolean;
79
75
  error: Error | null;
80
76
  };
81
-
82
- interface UseGetTakerCapacityOptions {
83
- client: Zkp2pClient | null;
84
- owner?: string | null;
85
- chainId?: number | null;
86
- autoFetch?: boolean;
87
- onSuccess?: (capacity: TakerCapacity) => void;
88
- onError?: (error: Error) => void;
89
- }
90
- /**
91
- * Fetches per-platform bonded taking capacity, free takes, and operational
92
- * gates for a taker's shared stake portfolio. Platform capacities are
93
- * alternative views of one shared balance — never sum them. Capacity can
94
- * change whenever any authorized relayer uses the shared stake, so refetch
95
- * immediately before signaling an intent; the contract stays authoritative.
96
- */
97
- declare function useGetTakerCapacity({ client, owner, chainId, autoFetch, onSuccess, onError, }: UseGetTakerCapacityOptions): {
98
- getTakerCapacity: (params?: GetTakerCapacityRequest) => Promise<GetTakerCapacityResponse | null>;
99
- takerCapacity: TakerCapacity | null;
100
- isLoading: boolean;
101
- error: Error | null;
77
+ declare function getNextTierCap(currentTier: string | undefined): string | null;
78
+ declare function getTierDisplayInfo(tier: TakerTier | undefined): {
79
+ tierLabel: string;
80
+ capDisplay: string;
81
+ isNewUser: boolean;
82
+ showScore: boolean;
102
83
  };
103
84
 
104
85
  interface UseFulfillIntentOptions {
@@ -338,6 +319,38 @@ declare function useSetVaultFee({ client, onSuccess, onError }: UseSetVaultFeeOp
338
319
  prepared: PreparedTransaction | null;
339
320
  };
340
321
 
322
+ interface UseExtendIntentLifetimeOptions {
323
+ client: Zkp2pClient | null;
324
+ onSuccess?: (hash: Hash) => void;
325
+ onError?: (error: Error, code: IntentGuardianErrorCode) => void;
326
+ }
327
+ /**
328
+ * Prepaid intent extension through the standalone IntentGuardian.
329
+ *
330
+ * The fee is owner-governed and can change at any time, so this hook never
331
+ * caches it: `refreshPolicy` and `quote` both read live state, and callers
332
+ * should re-quote immediately before signing and derive `maxCost` from that
333
+ * fresh result.
334
+ */
335
+ declare function useExtendIntentLifetime({ client, onSuccess, onError, }: UseExtendIntentLifetimeOptions): {
336
+ extendIntentLifetime: (params: Parameters<Zkp2pClient["extendIntentLifetime"]>[0]) => Promise<`0x${string}` | null>;
337
+ prepareExtendIntentLifetime: (params: Parameters<Zkp2pClient["extendIntentLifetime"]>[0]) => Promise<PreparedTransaction | null>;
338
+ refreshPolicy: () => Promise<IntentGuardianPolicy | null>;
339
+ refreshQuote: (params: {
340
+ intentAmount: bigint;
341
+ additionalTime: bigint;
342
+ }) => Promise<IntentGuardianQuote | null>;
343
+ policy: IntentGuardianPolicy | null;
344
+ quote: IntentGuardianQuote | null;
345
+ isLoading: boolean;
346
+ error: Error | null;
347
+ errorCode: IntentGuardianErrorCode | null;
348
+ txHash: `0x${string}` | null;
349
+ prepared: PreparedTransaction | null;
350
+ /** False where no guardian is deployed; hide the extension action entirely. */
351
+ isAvailable: boolean;
352
+ };
353
+
341
354
  interface UseSetVaultMinRateOptions {
342
355
  client: Zkp2pClient | null;
343
356
  onSuccess?: (hash: Hash) => void;
@@ -450,4 +463,4 @@ declare function usePruneExpiredIntents({ client, onSuccess, onError }: UsePrune
450
463
  txHash: `0x${string}` | null;
451
464
  };
452
465
 
453
- export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseFulfillIntentOptions, type UseGetTakerCapacityOptions, type UseGetTakerStakeOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerCapacity, useGetTakerStake, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
466
+ export { BatchResult, type CreateVaultParams, DelegationDepositTarget, PreparedTransaction, SendBatchFn, SendTransactionFn, type UseAddCurrenciesOptions, type UseAddFundsOptions, type UseAddPaymentMethodsOptions, type UseCreateDepositOptions, type UseCreateVaultOptions, type UseDeactivateCurrencyOptions, type UseExtendIntentLifetimeOptions, type UseFulfillIntentOptions, type UseGetTakerTierOptions, type UsePruneExpiredIntentsOptions, type UseReleaseFundsToPayerOptions, type UseRemoveCurrencyOptions, type UseRemoveDelegateOptions, type UseRemoveFundsOptions, type UseRemovePaymentMethodOptions, type UseSetAcceptingIntentsOptions, type UseSetCurrencyMinRateOptions, type UseSetDelegateOptions, type UseSetIntentRangeOptions, type UseSetPaymentMethodActiveOptions, type UseSetRetainOnEmptyOptions, type UseSetVaultConfigOptions, type UseSetVaultFeeOptions, type UseSetVaultMinRateOptions, type UseSignalIntentOptions, type UseVaultDelegationOptions, type UseWithdrawDepositOptions, getNextTierCap, getTierDisplayInfo, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useExtendIntentLifetime, useFulfillIntent, useGetTakerTier, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
package/dist/react.mjs CHANGED
@@ -1,7 +1,8 @@
1
- import { asErrorMessage, ZERO_ADDRESS, getDelegationRoute, assertDelegationMethodSupport, prepareClearDelegationTx, normalizeRateManagerId, normalizeRegistry, isZeroRateManagerId, assertAtomicDelegationSwitchSupport, prepareSetDelegationTx } from './chunk-LPJE2MN7.mjs';
2
- export { ZERO_ADDRESS as VAULT_ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-LPJE2MN7.mjs';
1
+ import { getNextTakerTier, TAKER_TIER_CAPS, asErrorMessage, ZERO_ADDRESS, getDelegationRoute, assertDelegationMethodSupport, prepareClearDelegationTx, normalizeRateManagerId, normalizeRegistry, isZeroRateManagerId, assertAtomicDelegationSwitchSupport, prepareSetDelegationTx, classifyIntentGuardianError } from './chunk-WXEP544Y.mjs';
2
+ export { ZERO_ADDRESS as VAULT_ZERO_ADDRESS, ZERO_RATE_MANAGER_ID, asErrorMessage, assertDelegationMethodSupport, classifyDelegationState, getDelegationRoute, isZeroRateManagerId, normalizeRateManagerId, normalizeRegistry } from './chunk-WXEP544Y.mjs';
3
3
  import './chunk-J5LGTIGS.mjs';
4
- import { useState, useCallback, useMemo, useRef, useEffect } from 'react';
4
+ import { useState, useCallback, useMemo, useEffect } from 'react';
5
+ import { formatUnits } from 'viem';
5
6
 
6
7
  function useCreateDeposit({ client, onSuccess, onError }) {
7
8
  const [isLoading, setIsLoading] = useState(false);
@@ -105,7 +106,7 @@ function useSignalIntent({ client, onSuccess, onError }) {
105
106
  [signalIntent, prepareSignalIntent, isLoading, error, txHash, prepared]
106
107
  );
107
108
  }
108
- function useGetTakerStake({
109
+ function useGetTakerTier({
109
110
  client,
110
111
  owner,
111
112
  chainId,
@@ -115,129 +116,97 @@ function useGetTakerStake({
115
116
  }) {
116
117
  const [isLoading, setIsLoading] = useState(false);
117
118
  const [error, setError] = useState(null);
118
- const [takerStake, setTakerStake] = useState(null);
119
- const onSuccessRef = useRef(onSuccess);
120
- const onErrorRef = useRef(onError);
121
- useEffect(() => {
122
- onSuccessRef.current = onSuccess;
123
- onErrorRef.current = onError;
124
- });
125
- const requestSeqRef = useRef(0);
126
- const getTakerStake = useCallback(
119
+ const [takerTier, setTakerTier] = useState(null);
120
+ const getTakerTier = useCallback(
127
121
  async (params) => {
128
122
  if (!client) {
129
123
  const err = new Error("Zkp2pClient is not initialized");
130
124
  setError(err);
131
- onErrorRef.current?.(err);
125
+ onError?.(err);
132
126
  return null;
133
127
  }
134
128
  const request = params ?? (owner && chainId ? { owner, chainId } : null);
135
129
  if (!request) {
136
130
  const err = new Error("Owner address and chainId are required");
137
131
  setError(err);
138
- onErrorRef.current?.(err);
132
+ onError?.(err);
139
133
  return null;
140
134
  }
141
- const requestId = ++requestSeqRef.current;
142
135
  setIsLoading(true);
143
136
  setError(null);
144
- setTakerStake(null);
137
+ setTakerTier(null);
145
138
  try {
146
- const response = await client.getTakerStake(request);
147
- if (requestId !== requestSeqRef.current) return null;
148
- if (!response.success || !response.responseObject) {
149
- throw new Error(response.message || "Taker stake request failed");
150
- }
151
- setTakerStake(response.responseObject);
152
- onSuccessRef.current?.(response.responseObject);
139
+ const response = await client.getTakerTier(request);
140
+ setTakerTier(response.responseObject);
141
+ onSuccess?.(response.responseObject);
153
142
  return response;
154
143
  } catch (err) {
155
- if (requestId !== requestSeqRef.current) return null;
156
144
  const e = err instanceof Error ? err : new Error(String(err));
157
145
  setError(e);
158
- onErrorRef.current?.(e);
146
+ onError?.(e);
159
147
  return null;
160
148
  } finally {
161
- if (requestId === requestSeqRef.current) setIsLoading(false);
149
+ setIsLoading(false);
162
150
  }
163
151
  },
164
- [client, owner, chainId]
152
+ [client, owner, chainId, onSuccess, onError]
165
153
  );
166
154
  useEffect(() => {
167
155
  if (!autoFetch || !owner || !chainId) return;
168
- void getTakerStake({ owner, chainId });
169
- }, [autoFetch, owner, chainId, getTakerStake]);
156
+ void getTakerTier({ owner, chainId });
157
+ }, [autoFetch, owner, chainId, getTakerTier]);
170
158
  return useMemo(
171
- () => ({ getTakerStake, takerStake, isLoading, error }),
172
- [getTakerStake, takerStake, isLoading, error]
159
+ () => ({ getTakerTier, takerTier, isLoading, error }),
160
+ [getTakerTier, takerTier, isLoading, error]
173
161
  );
174
162
  }
175
- function useGetTakerCapacity({
176
- client,
177
- owner,
178
- chainId,
179
- autoFetch = true,
180
- onSuccess,
181
- onError
182
- }) {
183
- const [isLoading, setIsLoading] = useState(false);
184
- const [error, setError] = useState(null);
185
- const [takerCapacity, setTakerCapacity] = useState(null);
186
- const onSuccessRef = useRef(onSuccess);
187
- const onErrorRef = useRef(onError);
188
- useEffect(() => {
189
- onSuccessRef.current = onSuccess;
190
- onErrorRef.current = onError;
191
- });
192
- const requestSeqRef = useRef(0);
193
- const getTakerCapacity = useCallback(
194
- async (params) => {
195
- if (!client) {
196
- const err = new Error("Zkp2pClient is not initialized");
197
- setError(err);
198
- onErrorRef.current?.(err);
199
- return null;
200
- }
201
- const request = params ?? (owner && chainId ? { owner, chainId } : null);
202
- if (!request) {
203
- const err = new Error("Owner address and chainId are required");
204
- setError(err);
205
- onErrorRef.current?.(err);
206
- return null;
207
- }
208
- const requestId = ++requestSeqRef.current;
209
- setIsLoading(true);
210
- setError(null);
211
- setTakerCapacity(null);
212
- try {
213
- const response = await client.getTakerCapacity(request);
214
- if (requestId !== requestSeqRef.current) return null;
215
- if (!response.success || !response.responseObject) {
216
- throw new Error(response.message || "Taker capacity request failed");
217
- }
218
- setTakerCapacity(response.responseObject);
219
- onSuccessRef.current?.(response.responseObject);
220
- return response;
221
- } catch (err) {
222
- if (requestId !== requestSeqRef.current) return null;
223
- const e = err instanceof Error ? err : new Error(String(err));
224
- setError(e);
225
- onErrorRef.current?.(e);
226
- return null;
227
- } finally {
228
- if (requestId === requestSeqRef.current) setIsLoading(false);
229
- }
230
- },
231
- [client, owner, chainId]
232
- );
233
- useEffect(() => {
234
- if (!autoFetch || !owner || !chainId) return;
235
- void getTakerCapacity({ owner, chainId });
236
- }, [autoFetch, owner, chainId, getTakerCapacity]);
237
- return useMemo(
238
- () => ({ getTakerCapacity, takerCapacity, isLoading, error }),
239
- [getTakerCapacity, takerCapacity, isLoading, error]
240
- );
163
+ function getNextTierCap(currentTier) {
164
+ const nextTier = getNextTakerTier(currentTier);
165
+ if (!nextTier) return null;
166
+ const nextCap = TAKER_TIER_CAPS[nextTier];
167
+ return nextCap != null ? `$${nextCap.toLocaleString()}` : null;
168
+ }
169
+ function formatCapFromBaseUnits(baseUnits) {
170
+ if (!baseUnits || baseUnits === "") return "$0";
171
+ const value = Number(formatUnits(BigInt(baseUnits), 6));
172
+ return `$${value.toLocaleString()}`;
173
+ }
174
+ function getCapForDisplay(tier) {
175
+ const platformLimits = tier.platformLimits ?? [];
176
+ if (platformLimits.length === 0) {
177
+ return tier.perIntentCapBaseUnits ?? tier.maxOrderSize;
178
+ }
179
+ const bestCap = platformLimits.filter((limit) => !limit.isLocked && limit.effectiveCap && limit.effectiveCap !== "0").reduce((current, limit) => {
180
+ if (!current) return limit.effectiveCap;
181
+ return BigInt(limit.effectiveCap) > BigInt(current) ? limit.effectiveCap : current;
182
+ }, void 0);
183
+ return bestCap ?? "0";
184
+ }
185
+ function getTierDisplayInfo(tier) {
186
+ if (!tier) {
187
+ return {
188
+ tierLabel: "Loading...",
189
+ capDisplay: "...",
190
+ isNewUser: false,
191
+ showScore: false
192
+ };
193
+ }
194
+ const isNewUser = tier.source === "fallback";
195
+ const isZeroFulfills = tier.stats?.lifetimeFulfilledCount === 0;
196
+ const tierLabels = {
197
+ PEASANT: "Peer Peasant",
198
+ PEER: "Peer",
199
+ PLUS: "Peer Plus",
200
+ PRO: "Peer Pro",
201
+ PLATINUM: "Peer Platinum"
202
+ };
203
+ const capDisplay = formatCapFromBaseUnits(getCapForDisplay(tier));
204
+ return {
205
+ tierLabel: tierLabels[tier.tier] || tier.tier,
206
+ capDisplay,
207
+ isNewUser: isNewUser || isZeroFulfills,
208
+ showScore: !isNewUser && !!tier.stats && tier.stats.lockScoreDiluted !== "0"
209
+ };
241
210
  }
242
211
  function useFulfillIntent({ client, onSuccess, onError }) {
243
212
  const [isLoading, setIsLoading] = useState(false);
@@ -1140,6 +1109,129 @@ function useSetVaultFee({ client, onSuccess, onError }) {
1140
1109
  [setVaultFee, prepareSetVaultFee, isLoading, error, txHash, prepared]
1141
1110
  );
1142
1111
  }
1112
+ function useExtendIntentLifetime({
1113
+ client,
1114
+ onSuccess,
1115
+ onError
1116
+ }) {
1117
+ const [isLoading, setIsLoading] = useState(false);
1118
+ const [error, setError] = useState(null);
1119
+ const [errorCode, setErrorCode] = useState(null);
1120
+ const [txHash, setTxHash] = useState(null);
1121
+ const [prepared, setPrepared] = useState(null);
1122
+ const [policy, setPolicy] = useState(null);
1123
+ const [quote, setQuote] = useState(null);
1124
+ const fail = useCallback(
1125
+ (err) => {
1126
+ const e = err instanceof Error ? err : new Error(String(err));
1127
+ const code = classifyIntentGuardianError(e);
1128
+ setError(e);
1129
+ setErrorCode(code);
1130
+ onError?.(e, code);
1131
+ return null;
1132
+ },
1133
+ [onError]
1134
+ );
1135
+ const requireClient = useCallback(() => {
1136
+ if (!client) {
1137
+ fail(new Error("Zkp2pClient is not initialized"));
1138
+ return null;
1139
+ }
1140
+ return client;
1141
+ }, [client, fail]);
1142
+ const refreshPolicy = useCallback(async () => {
1143
+ const c = requireClient();
1144
+ if (!c) return null;
1145
+ setIsLoading(true);
1146
+ setError(null);
1147
+ setErrorCode(null);
1148
+ try {
1149
+ const next = await c.getIntentGuardianPolicy();
1150
+ setPolicy(next);
1151
+ return next;
1152
+ } catch (err) {
1153
+ return fail(err);
1154
+ } finally {
1155
+ setIsLoading(false);
1156
+ }
1157
+ }, [requireClient, fail]);
1158
+ const refreshQuote = useCallback(
1159
+ async (params) => {
1160
+ setQuote(null);
1161
+ const c = requireClient();
1162
+ if (!c) return null;
1163
+ setIsLoading(true);
1164
+ setError(null);
1165
+ setErrorCode(null);
1166
+ try {
1167
+ const next = await c.quoteIntentExtension(params);
1168
+ setQuote(next);
1169
+ return next;
1170
+ } catch (err) {
1171
+ return fail(err);
1172
+ } finally {
1173
+ setIsLoading(false);
1174
+ }
1175
+ },
1176
+ [requireClient, fail]
1177
+ );
1178
+ const extendIntentLifetime = useCallback(
1179
+ async (params) => {
1180
+ const c = requireClient();
1181
+ if (!c) return null;
1182
+ setIsLoading(true);
1183
+ setError(null);
1184
+ setErrorCode(null);
1185
+ setTxHash(null);
1186
+ try {
1187
+ const hash = await c.extendIntentLifetime(params);
1188
+ setTxHash(hash);
1189
+ onSuccess?.(hash);
1190
+ return hash;
1191
+ } catch (err) {
1192
+ return fail(err);
1193
+ } finally {
1194
+ setIsLoading(false);
1195
+ }
1196
+ },
1197
+ [requireClient, fail, onSuccess]
1198
+ );
1199
+ const prepareExtendIntentLifetime = useCallback(
1200
+ async (params) => {
1201
+ const c = requireClient();
1202
+ if (!c) return null;
1203
+ setIsLoading(true);
1204
+ setError(null);
1205
+ setErrorCode(null);
1206
+ setPrepared(null);
1207
+ try {
1208
+ const tx = await c.extendIntentLifetime.prepare(params);
1209
+ setPrepared(tx);
1210
+ return tx;
1211
+ } catch (err) {
1212
+ return fail(err);
1213
+ } finally {
1214
+ setIsLoading(false);
1215
+ }
1216
+ },
1217
+ [requireClient, fail]
1218
+ );
1219
+ return {
1220
+ extendIntentLifetime,
1221
+ prepareExtendIntentLifetime,
1222
+ refreshPolicy,
1223
+ refreshQuote,
1224
+ policy,
1225
+ quote,
1226
+ isLoading,
1227
+ error,
1228
+ errorCode,
1229
+ txHash,
1230
+ prepared,
1231
+ /** False where no guardian is deployed; hide the extension action entirely. */
1232
+ isAvailable: client?.hasIntentGuardian() ?? false
1233
+ };
1234
+ }
1143
1235
  function useSetVaultMinRate({ client, onSuccess, onError }) {
1144
1236
  const [isLoading, setIsLoading] = useState(false);
1145
1237
  const [error, setError] = useState(null);
@@ -1512,6 +1604,6 @@ function usePruneExpiredIntents({ client, onSuccess, onError }) {
1512
1604
  return useMemo(() => ({ pruneExpiredIntents, isLoading, error, txHash }), [pruneExpiredIntents, isLoading, error, txHash]);
1513
1605
  }
1514
1606
 
1515
- export { useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useFulfillIntent, useGetTakerCapacity, useGetTakerStake, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
1607
+ export { getNextTierCap, getTierDisplayInfo, useAddCurrencies, useAddFunds, useAddPaymentMethods, useCreateDeposit, useCreateVault, useDeactivateCurrency, useExtendIntentLifetime, useFulfillIntent, useGetTakerTier, usePruneExpiredIntents, useReleaseFundsToPayer, useRemoveCurrency, useRemoveDelegate, useRemoveFunds, useRemovePaymentMethod, useSetAcceptingIntents, useSetCurrencyMinRate, useSetDelegate, useSetIntentRange, useSetPaymentMethodActive, useSetRetainOnEmpty, useSetVaultConfig, useSetVaultFee, useSetVaultMinRate, useSignalIntent, useVaultDelegation, useWithdrawDeposit };
1516
1608
  //# sourceMappingURL=react.mjs.map
1517
1609
  //# sourceMappingURL=react.mjs.map