@dcentralab/d402-client 0.3.11 → 0.3.13

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.mts CHANGED
@@ -927,6 +927,43 @@ declare function executeWithdrawal(params: {
927
927
  account: Account;
928
928
  network?: SupportedNetwork;
929
929
  }): Promise<Hash>;
930
+ /**
931
+ * Withdraw all funds from settlement layer for a wallet.
932
+ *
933
+ * This function calls the wallet's withdrawAllFromSettlement function,
934
+ * which withdraws all available funds from the settlement layer for the given token.
935
+ * Can optionally send funds directly to the owner address.
936
+ *
937
+ * @param params - Transaction parameters
938
+ * @param params.walletClient - Viem WalletClient (from wagmi useWalletClient)
939
+ * @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
940
+ * @param params.tokenAddress - Token contract address to withdraw
941
+ * @param params.sendToOwner - If true, sends funds to owner; if false, keeps in wallet (default: true)
942
+ * @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
943
+ * @returns Transaction hash
944
+ *
945
+ * @example
946
+ * ```ts
947
+ * import { withdrawAllFromSettlement } from '@dcentralab/d402-client'
948
+ *
949
+ * const hash = await withdrawAllFromSettlement({
950
+ * walletClient,
951
+ * publicClient,
952
+ * tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // USDC
953
+ * network: 'sepolia'
954
+ * })
955
+ *
956
+ * console.log('Withdrawal transaction:', hash)
957
+ * ```
958
+ */
959
+ declare function withdrawAllFromSettlement(params: {
960
+ walletClient: WalletClient;
961
+ publicClient: PublicClient;
962
+ tokenAddress: Address;
963
+ walletAddress: Address;
964
+ sendToOwner?: boolean;
965
+ network?: SupportedNetwork;
966
+ }): Promise<Hash>;
930
967
 
931
968
  /**
932
969
  * MCP Session Management
@@ -1376,4 +1413,4 @@ declare class UnsupportedNetworkError extends PaymentError {
1376
1413
  constructor(network: string);
1377
1414
  }
1378
1415
 
1379
- export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
1416
+ export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs, withdrawAllFromSettlement };
package/dist/index.d.ts CHANGED
@@ -927,6 +927,43 @@ declare function executeWithdrawal(params: {
927
927
  account: Account;
928
928
  network?: SupportedNetwork;
929
929
  }): Promise<Hash>;
930
+ /**
931
+ * Withdraw all funds from settlement layer for a wallet.
932
+ *
933
+ * This function calls the wallet's withdrawAllFromSettlement function,
934
+ * which withdraws all available funds from the settlement layer for the given token.
935
+ * Can optionally send funds directly to the owner address.
936
+ *
937
+ * @param params - Transaction parameters
938
+ * @param params.walletClient - Viem WalletClient (from wagmi useWalletClient)
939
+ * @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
940
+ * @param params.tokenAddress - Token contract address to withdraw
941
+ * @param params.sendToOwner - If true, sends funds to owner; if false, keeps in wallet (default: true)
942
+ * @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
943
+ * @returns Transaction hash
944
+ *
945
+ * @example
946
+ * ```ts
947
+ * import { withdrawAllFromSettlement } from '@dcentralab/d402-client'
948
+ *
949
+ * const hash = await withdrawAllFromSettlement({
950
+ * walletClient,
951
+ * publicClient,
952
+ * tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // USDC
953
+ * network: 'sepolia'
954
+ * })
955
+ *
956
+ * console.log('Withdrawal transaction:', hash)
957
+ * ```
958
+ */
959
+ declare function withdrawAllFromSettlement(params: {
960
+ walletClient: WalletClient;
961
+ publicClient: PublicClient;
962
+ tokenAddress: Address;
963
+ walletAddress: Address;
964
+ sendToOwner?: boolean;
965
+ network?: SupportedNetwork;
966
+ }): Promise<Hash>;
930
967
 
931
968
  /**
932
969
  * MCP Session Management
@@ -1376,4 +1413,4 @@ declare class UnsupportedNetworkError extends PaymentError {
1376
1413
  constructor(network: string);
1377
1414
  }
1378
1415
 
1379
- export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
1416
+ export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, type JsonRpcPayload, type McpToolResult, MissingRequestConfigError, type ParsedMcpResponse, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, buildMcpHeaders, buildToolCallPayload, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, extractToolResult, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChain, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletEIP712Domain, getWalletInfo, getWalletsByOwner, getWithdrawalRequest, initMcpSession, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMcpResponse, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs, withdrawAllFromSettlement };
package/dist/index.js CHANGED
@@ -10717,6 +10717,49 @@ async function executeWithdrawal(params) {
10717
10717
  await publicClient.waitForTransactionReceipt({ hash });
10718
10718
  return hash;
10719
10719
  }
10720
+ async function withdrawAllFromSettlement(params) {
10721
+ const {
10722
+ walletClient,
10723
+ publicClient,
10724
+ tokenAddress,
10725
+ walletAddress,
10726
+ sendToOwner = true,
10727
+ network = "sepolia"
10728
+ } = params;
10729
+ if (!walletClient?.account) {
10730
+ throw new Error("Wallet account not found. Please connect your wallet.");
10731
+ }
10732
+ const account = walletClient.account;
10733
+ const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
10734
+ if (!walletAbi) {
10735
+ throw new Error(`IATPWallet ABI not found for network: ${network}`);
10736
+ }
10737
+ await publicClient.simulateContract({
10738
+ account,
10739
+ address: walletAddress,
10740
+ abi: walletAbi,
10741
+ functionName: "withdrawAllFromSettlement",
10742
+ args: [tokenAddress, sendToOwner]
10743
+ });
10744
+ const estimatedGas = await publicClient.estimateContractGas({
10745
+ address: walletAddress,
10746
+ abi: walletAbi,
10747
+ functionName: "withdrawAllFromSettlement",
10748
+ args: [tokenAddress, sendToOwner],
10749
+ account
10750
+ });
10751
+ const gasLimit = estimatedGas + estimatedGas / 5n;
10752
+ const hash = await walletClient.writeContract({
10753
+ address: walletAddress,
10754
+ abi: walletAbi,
10755
+ functionName: "withdrawAllFromSettlement",
10756
+ args: [tokenAddress, sendToOwner],
10757
+ account,
10758
+ gas: gasLimit
10759
+ });
10760
+ await publicClient.waitForTransactionReceipt({ hash });
10761
+ return hash;
10762
+ }
10720
10763
 
10721
10764
  // src/client/D402Client.ts
10722
10765
  var D402Client = class {
@@ -11097,5 +11140,6 @@ exports.signD402Payment = signD402Payment;
11097
11140
  exports.sortPaymentRequirements = sortPaymentRequirements;
11098
11141
  exports.usdToUsdc = usdToUsdc;
11099
11142
  exports.withdrawAllAvailableEpochs = withdrawAllAvailableEpochs;
11143
+ exports.withdrawAllFromSettlement = withdrawAllFromSettlement;
11100
11144
  //# sourceMappingURL=index.js.map
11101
11145
  //# sourceMappingURL=index.js.map