@dcentralab/d402-client 0.2.4 → 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 +41 -108
- package/dist/index.d.ts +41 -108
- package/dist/index.js +40 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
- package/LICENSE +0 -22
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http, createPublicClient, createWalletClient, decodeEventLog,
|
|
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,16 +5214,14 @@ 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
|
-
const { publicClient,
|
|
5218
|
+
const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
|
|
5236
5219
|
const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
|
|
5237
5220
|
if (!settlementConfig) {
|
|
5238
5221
|
throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
|
|
5239
5222
|
}
|
|
5240
5223
|
const balance = await publicClient.readContract({
|
|
5241
|
-
address:
|
|
5224
|
+
address: settlementConfig.address,
|
|
5242
5225
|
abi: settlementConfig.abi,
|
|
5243
5226
|
functionName: "getLockedBalanceForProvider",
|
|
5244
5227
|
args: [providerAddress, tokenAddress]
|
|
@@ -5246,20 +5229,55 @@ async function getLockedBalanceForProvider(params) {
|
|
|
5246
5229
|
return balance;
|
|
5247
5230
|
}
|
|
5248
5231
|
async function getUnlockedBalanceForProvider(params) {
|
|
5249
|
-
const { publicClient,
|
|
5232
|
+
const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
|
|
5250
5233
|
const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
|
|
5251
5234
|
if (!settlementConfig) {
|
|
5252
5235
|
throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
|
|
5253
5236
|
}
|
|
5254
5237
|
const balance = await publicClient.readContract({
|
|
5255
|
-
address:
|
|
5238
|
+
address: settlementConfig.address,
|
|
5256
5239
|
abi: settlementConfig.abi,
|
|
5257
5240
|
functionName: "getUnlockedBalanceForProvider",
|
|
5258
5241
|
args: [providerAddress, tokenAddress]
|
|
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,
|
|
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
|