@dcentralab/d402-client 0.3.10 → 0.3.12

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Traia
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/dist/index.d.mts CHANGED
@@ -1142,6 +1142,42 @@ declare function withdrawAllAvailableEpochs(params: {
1142
1142
  tokenAddress: Address;
1143
1143
  network?: SupportedNetwork;
1144
1144
  }): Promise<Hash>;
1145
+ /**
1146
+ * Withdraw all funds from settlement layer for a wallet.
1147
+ *
1148
+ * This function calls the wallet's withdrawAllFromSettlement function,
1149
+ * which withdraws all available funds from the settlement layer for the given token.
1150
+ * Can optionally send funds directly to the owner address.
1151
+ *
1152
+ * @param params - Transaction parameters
1153
+ * @param params.walletClient - Viem WalletClient (from wagmi useWalletClient)
1154
+ * @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
1155
+ * @param params.tokenAddress - Token contract address to withdraw
1156
+ * @param params.sendToOwner - If true, sends funds to owner; if false, keeps in wallet (default: true)
1157
+ * @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
1158
+ * @returns Transaction hash
1159
+ *
1160
+ * @example
1161
+ * ```ts
1162
+ * import { withdrawAllFromSettlement } from '@dcentralab/d402-client'
1163
+ *
1164
+ * const hash = await withdrawAllFromSettlement({
1165
+ * walletClient,
1166
+ * publicClient,
1167
+ * tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // USDC
1168
+ * network: 'sepolia'
1169
+ * })
1170
+ *
1171
+ * console.log('Withdrawal transaction:', hash)
1172
+ * ```
1173
+ */
1174
+ declare function withdrawAllFromSettlement(params: {
1175
+ walletClient: WalletClient;
1176
+ publicClient: PublicClient;
1177
+ tokenAddress: Address;
1178
+ sendToOwner?: boolean;
1179
+ network?: SupportedNetwork;
1180
+ }): Promise<Hash>;
1145
1181
 
1146
1182
  /**
1147
1183
  * Contract configuration and utilities.
@@ -1376,4 +1412,4 @@ declare class UnsupportedNetworkError extends PaymentError {
1376
1412
  constructor(network: string);
1377
1413
  }
1378
1414
 
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 };
1415
+ 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
@@ -1142,6 +1142,42 @@ declare function withdrawAllAvailableEpochs(params: {
1142
1142
  tokenAddress: Address;
1143
1143
  network?: SupportedNetwork;
1144
1144
  }): Promise<Hash>;
1145
+ /**
1146
+ * Withdraw all funds from settlement layer for a wallet.
1147
+ *
1148
+ * This function calls the wallet's withdrawAllFromSettlement function,
1149
+ * which withdraws all available funds from the settlement layer for the given token.
1150
+ * Can optionally send funds directly to the owner address.
1151
+ *
1152
+ * @param params - Transaction parameters
1153
+ * @param params.walletClient - Viem WalletClient (from wagmi useWalletClient)
1154
+ * @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
1155
+ * @param params.tokenAddress - Token contract address to withdraw
1156
+ * @param params.sendToOwner - If true, sends funds to owner; if false, keeps in wallet (default: true)
1157
+ * @param params.network - Network: "sepolia" | "arbitrum" (default: "sepolia")
1158
+ * @returns Transaction hash
1159
+ *
1160
+ * @example
1161
+ * ```ts
1162
+ * import { withdrawAllFromSettlement } from '@dcentralab/d402-client'
1163
+ *
1164
+ * const hash = await withdrawAllFromSettlement({
1165
+ * walletClient,
1166
+ * publicClient,
1167
+ * tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // USDC
1168
+ * network: 'sepolia'
1169
+ * })
1170
+ *
1171
+ * console.log('Withdrawal transaction:', hash)
1172
+ * ```
1173
+ */
1174
+ declare function withdrawAllFromSettlement(params: {
1175
+ walletClient: WalletClient;
1176
+ publicClient: PublicClient;
1177
+ tokenAddress: Address;
1178
+ sendToOwner?: boolean;
1179
+ network?: SupportedNetwork;
1180
+ }): Promise<Hash>;
1145
1181
 
1146
1182
  /**
1147
1183
  * Contract configuration and utilities.
@@ -1376,4 +1412,4 @@ declare class UnsupportedNetworkError extends PaymentError {
1376
1412
  constructor(network: string);
1377
1413
  }
1378
1414
 
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 };
1415
+ 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
@@ -11051,6 +11051,42 @@ async function withdrawAllAvailableEpochs(params) {
11051
11051
  await publicClient.waitForTransactionReceipt({ hash });
11052
11052
  return hash;
11053
11053
  }
11054
+ async function withdrawAllFromSettlement(params) {
11055
+ const { walletClient, publicClient, tokenAddress, sendToOwner = true, network = "sepolia" } = params;
11056
+ if (!walletClient?.account) {
11057
+ throw new Error("Wallet account not found. Please connect your wallet.");
11058
+ }
11059
+ const account = walletClient.account;
11060
+ const walletConfig = getContractConfig("IATPWallet" /* IATP_WALLET */, network);
11061
+ if (!walletConfig) {
11062
+ throw new Error(`IATPWallet contract not found for network: ${network}`);
11063
+ }
11064
+ await publicClient.simulateContract({
11065
+ account,
11066
+ address: walletConfig.address,
11067
+ abi: walletConfig.abi,
11068
+ functionName: "withdrawAllFromSettlement",
11069
+ args: [tokenAddress, sendToOwner]
11070
+ });
11071
+ const estimatedGas = await publicClient.estimateContractGas({
11072
+ address: walletConfig.address,
11073
+ abi: walletConfig.abi,
11074
+ functionName: "withdrawAllFromSettlement",
11075
+ args: [tokenAddress, sendToOwner],
11076
+ account
11077
+ });
11078
+ const gasLimit = estimatedGas + estimatedGas / 5n;
11079
+ const hash = await walletClient.writeContract({
11080
+ address: walletConfig.address,
11081
+ abi: walletConfig.abi,
11082
+ functionName: "withdrawAllFromSettlement",
11083
+ args: [tokenAddress, sendToOwner],
11084
+ account,
11085
+ gas: gasLimit
11086
+ });
11087
+ await publicClient.waitForTransactionReceipt({ hash });
11088
+ return hash;
11089
+ }
11054
11090
 
11055
11091
  // src/index.ts
11056
11092
  init_utils();
@@ -11097,5 +11133,6 @@ exports.signD402Payment = signD402Payment;
11097
11133
  exports.sortPaymentRequirements = sortPaymentRequirements;
11098
11134
  exports.usdToUsdc = usdToUsdc;
11099
11135
  exports.withdrawAllAvailableEpochs = withdrawAllAvailableEpochs;
11136
+ exports.withdrawAllFromSettlement = withdrawAllFromSettlement;
11100
11137
  //# sourceMappingURL=index.js.map
11101
11138
  //# sourceMappingURL=index.js.map