@dcentralab/d402-client 0.2.5 → 0.2.6

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
@@ -719,103 +719,6 @@ declare const EIP712_TYPES: {
719
719
  }];
720
720
  };
721
721
 
722
- /**
723
- * Contract configuration and utilities.
724
- *
725
- * Provides access to IATPWallet contract ABIs and deployed addresses.
726
- * Contract data is bundled directly in the package for reliability.
727
- */
728
- /**
729
- * Supported contract names.
730
- */
731
- declare enum ContractName {
732
- IATP_WALLET = "IATPWallet",
733
- IATP_WALLET_FACTORY = "IATPWalletFactory",
734
- IATP_SETTLEMENT_LAYER = "IATPSettlementLayer",
735
- ROLE_MANAGER = "RoleManager"
736
- }
737
- /**
738
- * Supported networks for contract deployments.
739
- */
740
- type SupportedContractNetwork = 'sepolia';
741
- /**
742
- * Get contract address for a given network.
743
- *
744
- * @param contractName - Name of the contract (use ContractName enum)
745
- * @param network - Network name (default: "sepolia")
746
- * @param useProxy - Use proxy address if true, implementation if false (default: true)
747
- * @returns Contract address as hex string, or null if not found
748
- *
749
- * @example
750
- * ```ts
751
- * const factoryAddr = getContractAddress(ContractName.IATP_WALLET_FACTORY, 'sepolia')
752
- * console.log(factoryAddr) // "0x15D83638E339a0f29283f6B93dC1bb90b8339078"
753
- * ```
754
- */
755
- declare function getContractAddress(contractName: string | ContractName, network?: SupportedContractNetwork, useProxy?: boolean): string | null;
756
- /**
757
- * Get contract ABI for a given network.
758
- *
759
- * @param contractName - Name of the contract (use ContractName enum)
760
- * @param network - Network name (default: "sepolia")
761
- * @returns Contract ABI as array of objects, or null if not found
762
- *
763
- * @example
764
- * ```ts
765
- * const factoryAbi = getContractAbi(ContractName.IATP_WALLET_FACTORY, 'sepolia')
766
- * console.log(factoryAbi.length) // Number of ABI entries
767
- * ```
768
- */
769
- declare function getContractAbi(contractName: string | ContractName, network?: SupportedContractNetwork): any[] | null;
770
- /**
771
- * Get contract configuration (address and ABI) for a network.
772
- *
773
- * @param contractName - Name of the contract
774
- * @param network - Network name (default: "sepolia")
775
- * @returns Object with address and abi, or null if not found
776
- *
777
- * @example
778
- * ```ts
779
- * const config = getContractConfig(ContractName.IATP_WALLET_FACTORY, 'sepolia')
780
- * if (config) {
781
- * console.log(config.address)
782
- * console.log(config.abi.length)
783
- * }
784
- * ```
785
- */
786
- declare function getContractConfig(contractName: string | ContractName, network?: SupportedContractNetwork): {
787
- address: string;
788
- abi: any[];
789
- } | null;
790
- /**
791
- * Get all contract addresses for a network.
792
- *
793
- * @param network - Network name
794
- * @returns Object with all contract addresses for the network
795
- *
796
- * @example
797
- * ```ts
798
- * const addresses = getAllContractAddresses('sepolia')
799
- * console.log(addresses.IATPWalletFactory)
800
- * ```
801
- */
802
- declare function getAllContractAddresses(network: SupportedContractNetwork): Record<string, string>;
803
- /**
804
- * Check if a contract is deployed on a network.
805
- *
806
- * @param contractName - Name of the contract
807
- * @param network - Network name
808
- * @returns True if contract exists on network
809
- *
810
- * @example
811
- * ```ts
812
- * if (isContractDeployed(ContractName.IATP_WALLET_FACTORY, 'sepolia')) {
813
- * // Contract is available
814
- * }
815
- * ```
816
- */
817
- declare function isContractDeployed(contractName: string | ContractName, network: SupportedContractNetwork): boolean;
818
-
819
722
  /**
820
723
  * IATPWallet creation and management
821
724
  *
@@ -1027,5 +930,39 @@ declare function getUnlockedBalanceForProvider(params: {
1027
930
  tokenAddress: Address;
1028
931
  network?: 'sepolia';
1029
932
  }): Promise<bigint>;
933
+ /**
934
+ * Withdraw all available epochs for a provider (utility agent).
935
+ *
936
+ * This function calls the settlement layer's withdrawAllAvailableEpochs function,
937
+ * which releases and withdraws funds from all available epochs for the given token.
938
+ * Only the provider themselves can call this function.
939
+ *
940
+ * @param params - Transaction parameters
941
+ * @param params.walletClient - Viem WalletClient (from wagmi useWalletClient)
942
+ * @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
943
+ * @param params.tokenAddress - Token contract address to withdraw
944
+ * @param params.network - Network (default: "sepolia")
945
+ * @returns Transaction hash
946
+ *
947
+ * @example
948
+ * ```ts
949
+ * import { withdrawAllAvailableEpochs } from '@dcentralab/d402-client'
950
+ *
951
+ * const hash = await withdrawAllAvailableEpochs({
952
+ * walletClient,
953
+ * publicClient,
954
+ * tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // USDC
955
+ * network: 'sepolia'
956
+ * })
957
+ *
958
+ * console.log('Withdrawal transaction:', hash)
959
+ * ```
960
+ */
961
+ declare function withdrawAllAvailableEpochs(params: {
962
+ walletClient: WalletClient;
963
+ publicClient: PublicClient;
964
+ tokenAddress: Address;
965
+ network?: 'sepolia';
966
+ }): Promise<Hash>;
1030
967
 
1031
- export { CHAIN_IDS, ContractName, D402Client, type D402ClientConfig, type D402Config, DEFAULT_VALIDITY_WINDOW_SECONDS, type EIP712Domain, EIP712_TYPES, Invalid402ResponseError, MissingRequestConfigError, NETWORKS, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedContractNetwork, type SupportedNetwork, TOKEN_ADDRESSES, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, findMatchingPaymentRequirement, formatMoney, generateNonce, getAllContractAddresses, getAvailableBalance, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, isContractDeployed, isValidAddress, normalizeAddress, parseMoney, parsePaymentRequirement, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc };
968
+ export { CHAIN_IDS, D402Client, type D402ClientConfig, type D402Config, DEFAULT_VALIDITY_WINDOW_SECONDS, type EIP712Domain, EIP712_TYPES, Invalid402ResponseError, MissingRequestConfigError, NETWORKS, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, TOKEN_ADDRESSES, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChainId, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, isValidAddress, normalizeAddress, parseMoney, parsePaymentRequirement, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
package/dist/index.d.ts CHANGED
@@ -719,103 +719,6 @@ declare const EIP712_TYPES: {
719
719
  }];
720
720
  };
721
721
 
722
- /**
723
- * Contract configuration and utilities.
724
- *
725
- * Provides access to IATPWallet contract ABIs and deployed addresses.
726
- * Contract data is bundled directly in the package for reliability.
727
- */
728
- /**
729
- * Supported contract names.
730
- */
731
- declare enum ContractName {
732
- IATP_WALLET = "IATPWallet",
733
- IATP_WALLET_FACTORY = "IATPWalletFactory",
734
- IATP_SETTLEMENT_LAYER = "IATPSettlementLayer",
735
- ROLE_MANAGER = "RoleManager"
736
- }
737
- /**
738
- * Supported networks for contract deployments.
739
- */
740
- type SupportedContractNetwork = 'sepolia';
741
- /**
742
- * Get contract address for a given network.
743
- *
744
- * @param contractName - Name of the contract (use ContractName enum)
745
- * @param network - Network name (default: "sepolia")
746
- * @param useProxy - Use proxy address if true, implementation if false (default: true)
747
- * @returns Contract address as hex string, or null if not found
748
- *
749
- * @example
750
- * ```ts
751
- * const factoryAddr = getContractAddress(ContractName.IATP_WALLET_FACTORY, 'sepolia')
752
- * console.log(factoryAddr) // "0x15D83638E339a0f29283f6B93dC1bb90b8339078"
753
- * ```
754
- */
755
- declare function getContractAddress(contractName: string | ContractName, network?: SupportedContractNetwork, useProxy?: boolean): string | null;
756
- /**
757
- * Get contract ABI for a given network.
758
- *
759
- * @param contractName - Name of the contract (use ContractName enum)
760
- * @param network - Network name (default: "sepolia")
761
- * @returns Contract ABI as array of objects, or null if not found
762
- *
763
- * @example
764
- * ```ts
765
- * const factoryAbi = getContractAbi(ContractName.IATP_WALLET_FACTORY, 'sepolia')
766
- * console.log(factoryAbi.length) // Number of ABI entries
767
- * ```
768
- */
769
- declare function getContractAbi(contractName: string | ContractName, network?: SupportedContractNetwork): any[] | null;
770
- /**
771
- * Get contract configuration (address and ABI) for a network.
772
- *
773
- * @param contractName - Name of the contract
774
- * @param network - Network name (default: "sepolia")
775
- * @returns Object with address and abi, or null if not found
776
- *
777
- * @example
778
- * ```ts
779
- * const config = getContractConfig(ContractName.IATP_WALLET_FACTORY, 'sepolia')
780
- * if (config) {
781
- * console.log(config.address)
782
- * console.log(config.abi.length)
783
- * }
784
- * ```
785
- */
786
- declare function getContractConfig(contractName: string | ContractName, network?: SupportedContractNetwork): {
787
- address: string;
788
- abi: any[];
789
- } | null;
790
- /**
791
- * Get all contract addresses for a network.
792
- *
793
- * @param network - Network name
794
- * @returns Object with all contract addresses for the network
795
- *
796
- * @example
797
- * ```ts
798
- * const addresses = getAllContractAddresses('sepolia')
799
- * console.log(addresses.IATPWalletFactory)
800
- * ```
801
- */
802
- declare function getAllContractAddresses(network: SupportedContractNetwork): Record<string, string>;
803
- /**
804
- * Check if a contract is deployed on a network.
805
- *
806
- * @param contractName - Name of the contract
807
- * @param network - Network name
808
- * @returns True if contract exists on network
809
- *
810
- * @example
811
- * ```ts
812
- * if (isContractDeployed(ContractName.IATP_WALLET_FACTORY, 'sepolia')) {
813
- * // Contract is available
814
- * }
815
- * ```
816
- */
817
- declare function isContractDeployed(contractName: string | ContractName, network: SupportedContractNetwork): boolean;
818
-
819
722
  /**
820
723
  * IATPWallet creation and management
821
724
  *
@@ -1027,5 +930,39 @@ declare function getUnlockedBalanceForProvider(params: {
1027
930
  tokenAddress: Address;
1028
931
  network?: 'sepolia';
1029
932
  }): Promise<bigint>;
933
+ /**
934
+ * Withdraw all available epochs for a provider (utility agent).
935
+ *
936
+ * This function calls the settlement layer's withdrawAllAvailableEpochs function,
937
+ * which releases and withdraws funds from all available epochs for the given token.
938
+ * Only the provider themselves can call this function.
939
+ *
940
+ * @param params - Transaction parameters
941
+ * @param params.walletClient - Viem WalletClient (from wagmi useWalletClient)
942
+ * @param params.publicClient - Viem PublicClient (from wagmi usePublicClient)
943
+ * @param params.tokenAddress - Token contract address to withdraw
944
+ * @param params.network - Network (default: "sepolia")
945
+ * @returns Transaction hash
946
+ *
947
+ * @example
948
+ * ```ts
949
+ * import { withdrawAllAvailableEpochs } from '@dcentralab/d402-client'
950
+ *
951
+ * const hash = await withdrawAllAvailableEpochs({
952
+ * walletClient,
953
+ * publicClient,
954
+ * tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238', // USDC
955
+ * network: 'sepolia'
956
+ * })
957
+ *
958
+ * console.log('Withdrawal transaction:', hash)
959
+ * ```
960
+ */
961
+ declare function withdrawAllAvailableEpochs(params: {
962
+ walletClient: WalletClient;
963
+ publicClient: PublicClient;
964
+ tokenAddress: Address;
965
+ network?: 'sepolia';
966
+ }): Promise<Hash>;
1030
967
 
1031
- export { CHAIN_IDS, ContractName, D402Client, type D402ClientConfig, type D402Config, DEFAULT_VALIDITY_WINDOW_SECONDS, type EIP712Domain, EIP712_TYPES, Invalid402ResponseError, MissingRequestConfigError, NETWORKS, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedContractNetwork, type SupportedNetwork, TOKEN_ADDRESSES, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, findMatchingPaymentRequirement, formatMoney, generateNonce, getAllContractAddresses, getAvailableBalance, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, isContractDeployed, isValidAddress, normalizeAddress, parseMoney, parsePaymentRequirement, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc };
968
+ export { CHAIN_IDS, D402Client, type D402ClientConfig, type D402Config, DEFAULT_VALIDITY_WINDOW_SECONDS, type EIP712Domain, EIP712_TYPES, Invalid402ResponseError, MissingRequestConfigError, NETWORKS, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, TOKEN_ADDRESSES, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChainId, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, isValidAddress, normalizeAddress, parseMoney, parsePaymentRequirement, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
package/dist/index.js CHANGED
@@ -4809,13 +4809,6 @@ var implementations_default = {
4809
4809
  };
4810
4810
 
4811
4811
  // src/contracts.ts
4812
- var ContractName = /* @__PURE__ */ ((ContractName2) => {
4813
- ContractName2["IATP_WALLET"] = "IATPWallet";
4814
- ContractName2["IATP_WALLET_FACTORY"] = "IATPWalletFactory";
4815
- ContractName2["IATP_SETTLEMENT_LAYER"] = "IATPSettlementLayer";
4816
- ContractName2["ROLE_MANAGER"] = "RoleManager";
4817
- return ContractName2;
4818
- })(ContractName || {});
4819
4812
  var ABIS = {
4820
4813
  sepolia: sepolia_default.sepolia || {}
4821
4814
  };
@@ -4844,14 +4837,6 @@ function getContractConfig(contractName, network = "sepolia") {
4844
4837
  }
4845
4838
  return { address, abi };
4846
4839
  }
4847
- function getAllContractAddresses(network) {
4848
- return PROXY_ADDRESSES[network] || {};
4849
- }
4850
- function isContractDeployed(contractName, network) {
4851
- const address = getContractAddress(contractName, network);
4852
- const abi = getContractAbi(contractName, network);
4853
- return address !== null && abi !== null;
4854
- }
4855
4840
 
4856
4841
  // src/wallet.ts
4857
4842
  async function createIATPWallet(params) {
@@ -5231,8 +5216,6 @@ init_encoder();
5231
5216
  init_utils();
5232
5217
  init_errors();
5233
5218
  init_constants();
5234
-
5235
- // src/settlement.ts
5236
5219
  async function getLockedBalanceForProvider(params) {
5237
5220
  const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
5238
5221
  const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
@@ -5261,8 +5244,42 @@ async function getUnlockedBalanceForProvider(params) {
5261
5244
  });
5262
5245
  return balance;
5263
5246
  }
5247
+ async function withdrawAllAvailableEpochs(params) {
5248
+ const { walletClient, publicClient, tokenAddress, network = "sepolia" } = params;
5249
+ if (!walletClient?.account) {
5250
+ throw new Error("Wallet account not found. Please connect your wallet.");
5251
+ }
5252
+ const account = walletClient.account;
5253
+ const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
5254
+ if (!settlementConfig) {
5255
+ throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
5256
+ }
5257
+ const data = viem.encodeFunctionData({
5258
+ abi: settlementConfig.abi,
5259
+ functionName: "withdrawAllAvailableEpochs",
5260
+ args: [tokenAddress]
5261
+ });
5262
+ const estimatedGas = await publicClient.estimateGas({
5263
+ account: account.address,
5264
+ to: settlementConfig.address,
5265
+ data
5266
+ });
5267
+ const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
5268
+ const { request } = await publicClient.simulateContract({
5269
+ account,
5270
+ address: settlementConfig.address,
5271
+ abi: settlementConfig.abi,
5272
+ functionName: "withdrawAllAvailableEpochs",
5273
+ args: [tokenAddress]
5274
+ });
5275
+ const hash = await walletClient.writeContract({
5276
+ ...request,
5277
+ gas: gasLimit
5278
+ });
5279
+ await publicClient.waitForTransactionReceipt({ hash });
5280
+ return hash;
5281
+ }
5264
5282
 
5265
- exports.ContractName = ContractName;
5266
5283
  exports.D402Client = D402Client;
5267
5284
  exports.createIATPWallet = createIATPWallet;
5268
5285
  exports.createPaymentSelector = createPaymentSelector;
@@ -5272,18 +5289,13 @@ exports.encodePayment = encodePayment;
5272
5289
  exports.findMatchingPaymentRequirement = findMatchingPaymentRequirement;
5273
5290
  exports.formatMoney = formatMoney;
5274
5291
  exports.generateNonce = generateNonce;
5275
- exports.getAllContractAddresses = getAllContractAddresses;
5276
5292
  exports.getAvailableBalance = getAvailableBalance;
5277
5293
  exports.getChainId = getChainId;
5278
- exports.getContractAbi = getContractAbi;
5279
- exports.getContractAddress = getContractAddress;
5280
- exports.getContractConfig = getContractConfig;
5281
5294
  exports.getCurrentTimestamp = getCurrentTimestamp;
5282
5295
  exports.getLockedBalanceForProvider = getLockedBalanceForProvider;
5283
5296
  exports.getUnlockedBalanceForProvider = getUnlockedBalanceForProvider;
5284
5297
  exports.getUsdcAddress = getUsdcAddress;
5285
5298
  exports.getWalletsByOwner = getWalletsByOwner;
5286
- exports.isContractDeployed = isContractDeployed;
5287
5299
  exports.isValidAddress = isValidAddress;
5288
5300
  exports.normalizeAddress = normalizeAddress;
5289
5301
  exports.parseMoney = parseMoney;
@@ -5292,5 +5304,6 @@ exports.selectPaymentRequirement = selectPaymentRequirement;
5292
5304
  exports.signD402Payment = signD402Payment;
5293
5305
  exports.sortPaymentRequirements = sortPaymentRequirements;
5294
5306
  exports.usdToUsdc = usdToUsdc;
5307
+ exports.withdrawAllAvailableEpochs = withdrawAllAvailableEpochs;
5295
5308
  //# sourceMappingURL=index.js.map
5296
5309
  //# sourceMappingURL=index.js.map