@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.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { http, createPublicClient, createWalletClient, decodeEventLog, isAddress, encodeFunctionData } from 'viem';
1
+ import { http, createPublicClient, createWalletClient, decodeEventLog, encodeFunctionData, isAddress } from 'viem';
2
2
  import { sepolia } from 'viem/chains';
3
3
 
4
4
  var __defProp = Object.defineProperty;
@@ -4807,13 +4807,6 @@ var implementations_default = {
4807
4807
  };
4808
4808
 
4809
4809
  // src/contracts.ts
4810
- var ContractName = /* @__PURE__ */ ((ContractName2) => {
4811
- ContractName2["IATP_WALLET"] = "IATPWallet";
4812
- ContractName2["IATP_WALLET_FACTORY"] = "IATPWalletFactory";
4813
- ContractName2["IATP_SETTLEMENT_LAYER"] = "IATPSettlementLayer";
4814
- ContractName2["ROLE_MANAGER"] = "RoleManager";
4815
- return ContractName2;
4816
- })(ContractName || {});
4817
4810
  var ABIS = {
4818
4811
  sepolia: sepolia_default.sepolia || {}
4819
4812
  };
@@ -4842,14 +4835,6 @@ function getContractConfig(contractName, network = "sepolia") {
4842
4835
  }
4843
4836
  return { address, abi };
4844
4837
  }
4845
- function getAllContractAddresses(network) {
4846
- return PROXY_ADDRESSES[network] || {};
4847
- }
4848
- function isContractDeployed(contractName, network) {
4849
- const address = getContractAddress(contractName, network);
4850
- const abi = getContractAbi(contractName, network);
4851
- return address !== null && abi !== null;
4852
- }
4853
4838
 
4854
4839
  // src/wallet.ts
4855
4840
  async function createIATPWallet(params) {
@@ -5229,8 +5214,6 @@ init_encoder();
5229
5214
  init_utils();
5230
5215
  init_errors();
5231
5216
  init_constants();
5232
-
5233
- // src/settlement.ts
5234
5217
  async function getLockedBalanceForProvider(params) {
5235
5218
  const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
5236
5219
  const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
@@ -5259,7 +5242,42 @@ async function getUnlockedBalanceForProvider(params) {
5259
5242
  });
5260
5243
  return balance;
5261
5244
  }
5245
+ async function withdrawAllAvailableEpochs(params) {
5246
+ const { walletClient, publicClient, tokenAddress, network = "sepolia" } = params;
5247
+ if (!walletClient?.account) {
5248
+ throw new Error("Wallet account not found. Please connect your wallet.");
5249
+ }
5250
+ const account = walletClient.account;
5251
+ const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
5252
+ if (!settlementConfig) {
5253
+ throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
5254
+ }
5255
+ const data = encodeFunctionData({
5256
+ abi: settlementConfig.abi,
5257
+ functionName: "withdrawAllAvailableEpochs",
5258
+ args: [tokenAddress]
5259
+ });
5260
+ const estimatedGas = await publicClient.estimateGas({
5261
+ account: account.address,
5262
+ to: settlementConfig.address,
5263
+ data
5264
+ });
5265
+ const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
5266
+ const { request } = await publicClient.simulateContract({
5267
+ account,
5268
+ address: settlementConfig.address,
5269
+ abi: settlementConfig.abi,
5270
+ functionName: "withdrawAllAvailableEpochs",
5271
+ args: [tokenAddress]
5272
+ });
5273
+ const hash = await walletClient.writeContract({
5274
+ ...request,
5275
+ gas: gasLimit
5276
+ });
5277
+ await publicClient.waitForTransactionReceipt({ hash });
5278
+ return hash;
5279
+ }
5262
5280
 
5263
- export { CHAIN_IDS, ContractName, D402Client, DEFAULT_VALIDITY_WINDOW_SECONDS, EIP712_TYPES, Invalid402ResponseError, MissingRequestConfigError, NETWORKS, PaymentAlreadyAttemptedError, PaymentAmountExceededError, PaymentError, PaymentVerificationError, TOKEN_ADDRESSES, UnsupportedNetworkError, UnsupportedSchemeError, 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 };
5281
+ export { CHAIN_IDS, D402Client, DEFAULT_VALIDITY_WINDOW_SECONDS, EIP712_TYPES, Invalid402ResponseError, MissingRequestConfigError, NETWORKS, PaymentAlreadyAttemptedError, PaymentAmountExceededError, PaymentError, PaymentVerificationError, TOKEN_ADDRESSES, UnsupportedNetworkError, UnsupportedSchemeError, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChainId, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, isValidAddress, normalizeAddress, parseMoney, parsePaymentRequirement, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
5264
5282
  //# sourceMappingURL=index.mjs.map
5265
5283
  //# sourceMappingURL=index.mjs.map