@unlink-xyz/react 0.1.3-canary.b90837a → 0.1.3-canary.ffa8bc4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as react_jsx_runtime from 'react/jsx-runtime';
2
2
  import { ReactNode } from 'react';
3
- import { BrowserWalletOptions, Environment, UnlinkWallet, AccountInfo, Account, NoteRecord, HistoryStatus, TransferResult, TransferPlanResult, DepositRelayResult, WithdrawalInput, WithdrawResult, WithdrawPlanResult, RelayState, HistoryEntry } from '@unlink-xyz/core';
4
- export { Account, AccountInfo, Chain, HistoryEntry, NoteRecord, ParsedZkAddress, TransferPlanResult, TransferResult, TxStatusChangedEvent, UnlinkWallet, WalletSDKEvent, WithdrawPlanResult, WithdrawResult, computeBalances, decodeAddress, encodeAddress, formatAmount, normalizeAddress, parseAmount, parseZkAddress, randomHex, shortenHex } from '@unlink-xyz/core';
3
+ import { BrowserWalletOptions, Environment, UnlinkWallet, AccountInfo, Account, NoteRecord, HistoryStatus, TransferResult, TransferPlanResult, DepositRelayResult, WithdrawalInput, WithdrawResult, WithdrawPlanResult, SimpleAdapterExecuteParams, AdapterExecuteResult, RelayState, HistoryEntry } from '@unlink-xyz/core';
4
+ export { Account, AccountInfo, AdapterExecuteResult, AdapterExecutionCall, Chain, HistoryEntry, InputTokenSpec, NoteRecord, ParsedZkAddress, ReshieldInput, SimpleAdapterExecuteParams, TransferPlanResult, TransferResult, TxStatusChangedEvent, UnlinkWallet, WalletSDKEvent, WithdrawPlanResult, WithdrawResult, computeBalances, decodeAddress, encodeAddress, formatAmount, normalizeAddress, parseAmount, parseZkAddress, randomHex, shortenHex } from '@unlink-xyz/core';
5
5
 
6
6
  /**
7
7
  * Wallet note with value as bigint for convenience.
@@ -181,6 +181,10 @@ type UnlinkActions = {
181
181
  planWithdraw(params: WithdrawInput[]): Promise<WithdrawPlanResult>;
182
182
  /** Execute a pre-built withdrawal plan */
183
183
  executeWithdraw(plans: WithdrawPlanResult): Promise<WithdrawResult>;
184
+ /**
185
+ * Execute an atomic private adapter flow (unshield -> calls -> reshield).
186
+ */
187
+ executeAdapter(params: SimpleAdapterExecuteParams): Promise<AdapterExecuteResult>;
184
188
  /** Refresh notes and balances */
185
189
  refresh(): Promise<void>;
186
190
  /** Force full resync from chain */
@@ -269,7 +273,7 @@ type UnlinkErrorCode = "UNKNOWN" | "SDK_NOT_INITIALIZED" | "NETWORK_ERROR" | "VA
269
273
  /**
270
274
  * Operations that can trigger an error in the Unlink context.
271
275
  */
272
- type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeWithdraw" | "refresh" | "forceResync";
276
+ type UnlinkErrorOperation = "init" | "createWallet" | "importWallet" | "clearWallet" | "createAccount" | "switchAccount" | "send" | "executeTransfer" | "requestDeposit" | "requestWithdraw" | "executeAdapter" | "executeWithdraw" | "refresh" | "forceResync";
273
277
  /**
274
278
  * Structured error type for the Unlink context.
275
279
  */
@@ -549,4 +553,34 @@ declare function useTransfer(): UseOperationMutationResult<TransferInput[], Tran
549
553
  */
550
554
  declare function useWithdraw(): UseOperationMutationResult<WithdrawInput[], WithdrawResult>;
551
555
 
552
- export { CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, type PendingDepositJob, type PendingTransferJob, type PendingWithdrawJob, TERMINAL_TX_STATES, TimeoutError, TransactionFailedError, type TransferInput, type TxState, type TxStatus, type UnlinkActions, type UnlinkConfig, type UnlinkContextValue, type UnlinkError, type UnlinkErrorCode, type UnlinkErrorOperation, UnlinkProvider, type UnlinkProviderProps, type UnlinkState, type UseOperationMutationResult, type UseTxStatusResult, type UseUnlinkBalanceResult, type UseUnlinkHistoryOptions, type UseUnlinkHistoryResult, type WaitForConfirmationOptions, type WalletNote, type WithdrawInput, useDeposit, useOperationMutation, useTransfer, useTxStatus, useUnlink, useUnlinkBalance, useUnlinkBalances, useUnlinkHistory, useWithdraw };
556
+ /**
557
+ * Hook for executing private DeFi adapter operations with loading/error state.
558
+ *
559
+ * Performs atomic unshield → DeFi call(s) → reshield flows through an adapter contract.
560
+ *
561
+ * @example
562
+ * ```tsx
563
+ * function SwapButton() {
564
+ * const { mutate: executeAdapter, isPending, error } = useAdapter();
565
+ *
566
+ * const handleSwap = async () => {
567
+ * const result = await executeAdapter({
568
+ * adapterAddress: "0x...",
569
+ * inputs: [{ token: "0x...", amount: 1000n }],
570
+ * calls: [approveCall, swapCall],
571
+ * reshields: [{ token: "0x...", minAmount: 500n }],
572
+ * });
573
+ * console.log("Relay ID:", result.relayId);
574
+ * };
575
+ *
576
+ * return (
577
+ * <button onClick={handleSwap} disabled={isPending}>
578
+ * {isPending ? "Executing..." : "Swap"}
579
+ * </button>
580
+ * );
581
+ * }
582
+ * ```
583
+ */
584
+ declare function useAdapter(): UseOperationMutationResult<SimpleAdapterExecuteParams, AdapterExecuteResult>;
585
+
586
+ export { CONFIRMATION_POLL_INTERVAL_MS, DEFAULT_CONFIRMATION_TIMEOUT_MS, type DepositInput, type PendingDepositJob, type PendingTransferJob, type PendingWithdrawJob, TERMINAL_TX_STATES, TimeoutError, TransactionFailedError, type TransferInput, type TxState, type TxStatus, type UnlinkActions, type UnlinkConfig, type UnlinkContextValue, type UnlinkError, type UnlinkErrorCode, type UnlinkErrorOperation, UnlinkProvider, type UnlinkProviderProps, type UnlinkState, type UseOperationMutationResult, type UseTxStatusResult, type UseUnlinkBalanceResult, type UseUnlinkHistoryOptions, type UseUnlinkHistoryResult, type WaitForConfirmationOptions, type WalletNote, type WithdrawInput, useAdapter, useDeposit, useOperationMutation, useTransfer, useTxStatus, useUnlink, useUnlinkBalance, useUnlinkBalances, useUnlinkHistory, useWithdraw };
package/dist/index.js CHANGED
@@ -57475,6 +57475,36 @@ function UnlinkProvider({
57475
57475
  },
57476
57476
  []
57477
57477
  );
57478
+ const executeAdapter = useCallback(
57479
+ async (params) => {
57480
+ const wallet = walletRef.current;
57481
+ if (!wallet) throw new Error("SDK not initialized");
57482
+ setState((prev2) => ({
57483
+ ...prev2,
57484
+ busy: true,
57485
+ status: "Executing adapter..."
57486
+ }));
57487
+ try {
57488
+ const result = await wallet.adapter.execute(params);
57489
+ setState((prev2) => ({
57490
+ ...prev2,
57491
+ busy: false,
57492
+ status: "Adapter execution submitted",
57493
+ error: null
57494
+ }));
57495
+ return result;
57496
+ } catch (err) {
57497
+ setState((prev2) => ({
57498
+ ...prev2,
57499
+ busy: false,
57500
+ status: `Error: ${err instanceof Error ? err.message : "Unknown"}`,
57501
+ error: createUnlinkError(err, "executeAdapter")
57502
+ }));
57503
+ throw err;
57504
+ }
57505
+ },
57506
+ []
57507
+ );
57478
57508
  const planWithdraw = useCallback(
57479
57509
  async (params) => {
57480
57510
  const wallet = walletRef.current;
@@ -57648,6 +57678,8 @@ function UnlinkProvider({
57648
57678
  requestDeposit,
57649
57679
  // Withdraw actions
57650
57680
  requestWithdraw,
57681
+ // Adapter actions
57682
+ executeAdapter,
57651
57683
  planWithdraw,
57652
57684
  executeWithdraw,
57653
57685
  // Sync actions
@@ -57673,6 +57705,7 @@ function UnlinkProvider({
57673
57705
  executeTransfer,
57674
57706
  requestDeposit,
57675
57707
  requestWithdraw,
57708
+ executeAdapter,
57676
57709
  planWithdraw,
57677
57710
  executeWithdraw,
57678
57711
  refresh,
@@ -57910,6 +57943,17 @@ function useWithdraw() {
57910
57943
  );
57911
57944
  return useOperationMutation(op);
57912
57945
  }
57946
+
57947
+ // src/useAdapter.ts
57948
+ import { useCallback as useCallback8 } from "react";
57949
+ function useAdapter() {
57950
+ const { executeAdapter } = useUnlink();
57951
+ const op = useCallback8(
57952
+ (params) => executeAdapter(params),
57953
+ [executeAdapter]
57954
+ );
57955
+ return useOperationMutation(op);
57956
+ }
57913
57957
  export {
57914
57958
  CONFIRMATION_POLL_INTERVAL_MS,
57915
57959
  DEFAULT_CONFIRMATION_TIMEOUT_MS,
@@ -57926,6 +57970,7 @@ export {
57926
57970
  parseZkAddress,
57927
57971
  randomHex,
57928
57972
  shortenHex,
57973
+ useAdapter,
57929
57974
  useDeposit,
57930
57975
  useOperationMutation,
57931
57976
  useTransfer,