@dcentralab/d402-client 0.3.2 → 0.3.4
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 +31 -15
- package/dist/index.d.ts +31 -15
- package/dist/index.js +27 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -23
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/dist/index.d.mts
CHANGED
|
@@ -187,11 +187,6 @@ declare function sortPaymentRequirements(requirements: PaymentRequirement[], pre
|
|
|
187
187
|
*/
|
|
188
188
|
declare function findMatchingPaymentRequirement(requirements: PaymentRequirement[], scheme?: string, network?: string): PaymentRequirement | undefined;
|
|
189
189
|
|
|
190
|
-
/**
|
|
191
|
-
* D402 Client - Main client class for handling HTTP 402 payments
|
|
192
|
-
*
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
190
|
/**
|
|
196
191
|
* D402 Client configuration.
|
|
197
192
|
*
|
|
@@ -333,9 +328,12 @@ declare class D402Client {
|
|
|
333
328
|
*
|
|
334
329
|
* @param publicClient - Viem PublicClient
|
|
335
330
|
* @param tokenAddress - Token contract address
|
|
336
|
-
* @returns Withdrawal request
|
|
331
|
+
* @returns Withdrawal request details (request + unlockTime) or null if no request exists
|
|
337
332
|
*/
|
|
338
|
-
getWithdrawalRequest(publicClient: PublicClient, tokenAddress: `0x${string}`): Promise<
|
|
333
|
+
getWithdrawalRequest(publicClient: PublicClient, tokenAddress: `0x${string}`): Promise<{
|
|
334
|
+
request: WithdrawalRequest;
|
|
335
|
+
unlockTime: bigint;
|
|
336
|
+
} | null>;
|
|
339
337
|
/**
|
|
340
338
|
* Request a withdrawal from the IATP wallet.
|
|
341
339
|
*
|
|
@@ -565,6 +563,15 @@ interface WalletCreationResult {
|
|
|
565
563
|
/** Chain ID */
|
|
566
564
|
chainId: number;
|
|
567
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Withdrawal request from an IATPWallet.
|
|
568
|
+
*/
|
|
569
|
+
interface WithdrawalRequest {
|
|
570
|
+
token: Address;
|
|
571
|
+
amount: bigint;
|
|
572
|
+
requestedAt: bigint;
|
|
573
|
+
executed: boolean;
|
|
574
|
+
}
|
|
568
575
|
|
|
569
576
|
/**
|
|
570
577
|
* IATPWallet creation functions
|
|
@@ -697,28 +704,34 @@ declare function getWalletsByOwner(params: {
|
|
|
697
704
|
* Get withdrawal request for a token in an IATPWallet.
|
|
698
705
|
*
|
|
699
706
|
* Queries the IATPWallet contract to get the current withdrawal request
|
|
700
|
-
*
|
|
707
|
+
* including all details: token, amount, requestedAt, executed status, and unlockTime.
|
|
701
708
|
*
|
|
702
709
|
* @param params - Query parameters
|
|
703
710
|
* @param params.publicClient - Viem PublicClient
|
|
704
711
|
* @param params.walletAddress - IATPWallet contract address
|
|
705
712
|
* @param params.tokenAddress - Token contract address
|
|
706
713
|
* @param params.network - Network to query (default: "sepolia")
|
|
707
|
-
* @returns Withdrawal request
|
|
714
|
+
* @returns Withdrawal request details or null if no request exists
|
|
708
715
|
*
|
|
709
716
|
* @example
|
|
710
717
|
* ```ts
|
|
711
718
|
* import { getWithdrawalRequest } from '@dcentralab/d402-client'
|
|
712
719
|
*
|
|
713
|
-
* const
|
|
720
|
+
* const result = await getWithdrawalRequest({
|
|
714
721
|
* publicClient,
|
|
715
722
|
* walletAddress: '0xUserIATPWallet...',
|
|
716
723
|
* tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
|
|
717
724
|
* })
|
|
718
725
|
*
|
|
719
|
-
* if (
|
|
720
|
-
* const
|
|
721
|
-
*
|
|
726
|
+
* if (result) {
|
|
727
|
+
* const { request, unlockTime } = result
|
|
728
|
+
* console.log('Token:', request.token)
|
|
729
|
+
* console.log('Amount:', request.amount)
|
|
730
|
+
* console.log('Requested at:', new Date(Number(request.requestedAt) * 1000))
|
|
731
|
+
* console.log('Executed:', request.executed)
|
|
732
|
+
* console.log('Unlocks at:', new Date(Number(unlockTime) * 1000))
|
|
733
|
+
*
|
|
734
|
+
* const isUnlocked = Date.now() >= Number(unlockTime) * 1000
|
|
722
735
|
* }
|
|
723
736
|
* ```
|
|
724
737
|
*/
|
|
@@ -727,7 +740,10 @@ declare function getWithdrawalRequest(params: {
|
|
|
727
740
|
walletAddress: Address;
|
|
728
741
|
tokenAddress: Address;
|
|
729
742
|
network?: 'sepolia';
|
|
730
|
-
}): Promise<
|
|
743
|
+
}): Promise<{
|
|
744
|
+
request: WithdrawalRequest;
|
|
745
|
+
unlockTime: bigint;
|
|
746
|
+
} | null>;
|
|
731
747
|
/**
|
|
732
748
|
* Request a withdrawal from an IATPWallet.
|
|
733
749
|
*
|
|
@@ -1156,4 +1172,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1156
1172
|
constructor(network: string);
|
|
1157
1173
|
}
|
|
1158
1174
|
|
|
1159
|
-
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, MissingRequestConfigError, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, getWithdrawalRequest, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
|
|
1175
|
+
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, MissingRequestConfigError, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, getWithdrawalRequest, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
|
package/dist/index.d.ts
CHANGED
|
@@ -187,11 +187,6 @@ declare function sortPaymentRequirements(requirements: PaymentRequirement[], pre
|
|
|
187
187
|
*/
|
|
188
188
|
declare function findMatchingPaymentRequirement(requirements: PaymentRequirement[], scheme?: string, network?: string): PaymentRequirement | undefined;
|
|
189
189
|
|
|
190
|
-
/**
|
|
191
|
-
* D402 Client - Main client class for handling HTTP 402 payments
|
|
192
|
-
*
|
|
193
|
-
*/
|
|
194
|
-
|
|
195
190
|
/**
|
|
196
191
|
* D402 Client configuration.
|
|
197
192
|
*
|
|
@@ -333,9 +328,12 @@ declare class D402Client {
|
|
|
333
328
|
*
|
|
334
329
|
* @param publicClient - Viem PublicClient
|
|
335
330
|
* @param tokenAddress - Token contract address
|
|
336
|
-
* @returns Withdrawal request
|
|
331
|
+
* @returns Withdrawal request details (request + unlockTime) or null if no request exists
|
|
337
332
|
*/
|
|
338
|
-
getWithdrawalRequest(publicClient: PublicClient, tokenAddress: `0x${string}`): Promise<
|
|
333
|
+
getWithdrawalRequest(publicClient: PublicClient, tokenAddress: `0x${string}`): Promise<{
|
|
334
|
+
request: WithdrawalRequest;
|
|
335
|
+
unlockTime: bigint;
|
|
336
|
+
} | null>;
|
|
339
337
|
/**
|
|
340
338
|
* Request a withdrawal from the IATP wallet.
|
|
341
339
|
*
|
|
@@ -565,6 +563,15 @@ interface WalletCreationResult {
|
|
|
565
563
|
/** Chain ID */
|
|
566
564
|
chainId: number;
|
|
567
565
|
}
|
|
566
|
+
/**
|
|
567
|
+
* Withdrawal request from an IATPWallet.
|
|
568
|
+
*/
|
|
569
|
+
interface WithdrawalRequest {
|
|
570
|
+
token: Address;
|
|
571
|
+
amount: bigint;
|
|
572
|
+
requestedAt: bigint;
|
|
573
|
+
executed: boolean;
|
|
574
|
+
}
|
|
568
575
|
|
|
569
576
|
/**
|
|
570
577
|
* IATPWallet creation functions
|
|
@@ -697,28 +704,34 @@ declare function getWalletsByOwner(params: {
|
|
|
697
704
|
* Get withdrawal request for a token in an IATPWallet.
|
|
698
705
|
*
|
|
699
706
|
* Queries the IATPWallet contract to get the current withdrawal request
|
|
700
|
-
*
|
|
707
|
+
* including all details: token, amount, requestedAt, executed status, and unlockTime.
|
|
701
708
|
*
|
|
702
709
|
* @param params - Query parameters
|
|
703
710
|
* @param params.publicClient - Viem PublicClient
|
|
704
711
|
* @param params.walletAddress - IATPWallet contract address
|
|
705
712
|
* @param params.tokenAddress - Token contract address
|
|
706
713
|
* @param params.network - Network to query (default: "sepolia")
|
|
707
|
-
* @returns Withdrawal request
|
|
714
|
+
* @returns Withdrawal request details or null if no request exists
|
|
708
715
|
*
|
|
709
716
|
* @example
|
|
710
717
|
* ```ts
|
|
711
718
|
* import { getWithdrawalRequest } from '@dcentralab/d402-client'
|
|
712
719
|
*
|
|
713
|
-
* const
|
|
720
|
+
* const result = await getWithdrawalRequest({
|
|
714
721
|
* publicClient,
|
|
715
722
|
* walletAddress: '0xUserIATPWallet...',
|
|
716
723
|
* tokenAddress: '0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238',
|
|
717
724
|
* })
|
|
718
725
|
*
|
|
719
|
-
* if (
|
|
720
|
-
* const
|
|
721
|
-
*
|
|
726
|
+
* if (result) {
|
|
727
|
+
* const { request, unlockTime } = result
|
|
728
|
+
* console.log('Token:', request.token)
|
|
729
|
+
* console.log('Amount:', request.amount)
|
|
730
|
+
* console.log('Requested at:', new Date(Number(request.requestedAt) * 1000))
|
|
731
|
+
* console.log('Executed:', request.executed)
|
|
732
|
+
* console.log('Unlocks at:', new Date(Number(unlockTime) * 1000))
|
|
733
|
+
*
|
|
734
|
+
* const isUnlocked = Date.now() >= Number(unlockTime) * 1000
|
|
722
735
|
* }
|
|
723
736
|
* ```
|
|
724
737
|
*/
|
|
@@ -727,7 +740,10 @@ declare function getWithdrawalRequest(params: {
|
|
|
727
740
|
walletAddress: Address;
|
|
728
741
|
tokenAddress: Address;
|
|
729
742
|
network?: 'sepolia';
|
|
730
|
-
}): Promise<
|
|
743
|
+
}): Promise<{
|
|
744
|
+
request: WithdrawalRequest;
|
|
745
|
+
unlockTime: bigint;
|
|
746
|
+
} | null>;
|
|
731
747
|
/**
|
|
732
748
|
* Request a withdrawal from an IATPWallet.
|
|
733
749
|
*
|
|
@@ -1156,4 +1172,4 @@ declare class UnsupportedNetworkError extends PaymentError {
|
|
|
1156
1172
|
constructor(network: string);
|
|
1157
1173
|
}
|
|
1158
1174
|
|
|
1159
|
-
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, MissingRequestConfigError, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, getWithdrawalRequest, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
|
|
1175
|
+
export { ContractName, D402Client, type D402ClientConfig, type D402Response, type EIP712Domain, Invalid402ResponseError, MissingRequestConfigError, PaymentAlreadyAttemptedError, PaymentAmountExceededError, type PaymentAuthorization, PaymentError, type PaymentRequirement, type PaymentSelector, type PaymentSelectorOptions, PaymentVerificationError, type SignedPayment, type SupportedNetwork, UnsupportedNetworkError, UnsupportedSchemeError, type WalletCreationResult, type WithdrawalRequest, createIATPWallet, createPaymentSelector, decodePayment, decodePaymentResponse, encodePayment, executeWithdrawal, findMatchingPaymentRequirement, formatMoney, generateNonce, getAvailableBalance, getChainId, getContractAbi, getContractAddress, getContractConfig, getCurrentTimestamp, getLockedBalanceForProvider, getUnlockedBalanceForProvider, getUsdcAddress, getWalletsByOwner, getWithdrawalRequest, isValidAddress, normalizeAddress, parseAllPaymentRequirements, parseMoney, parsePaymentRequirement, requestWithdrawal, selectPaymentRequirement, signD402Payment, sortPaymentRequirements, usdToUsdc, withdrawAllAvailableEpochs };
|
package/dist/index.js
CHANGED
|
@@ -5109,13 +5109,13 @@ async function createIATPWallet(params) {
|
|
|
5109
5109
|
}
|
|
5110
5110
|
async function getAvailableBalance(params) {
|
|
5111
5111
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
5112
|
-
const
|
|
5113
|
-
if (!
|
|
5114
|
-
throw new Error(`IATPWallet
|
|
5112
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5113
|
+
if (!walletAbi) {
|
|
5114
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5115
5115
|
}
|
|
5116
5116
|
const balance = await publicClient.readContract({
|
|
5117
5117
|
address: walletAddress,
|
|
5118
|
-
abi:
|
|
5118
|
+
abi: walletAbi,
|
|
5119
5119
|
functionName: "getAvailableBalance",
|
|
5120
5120
|
args: [tokenAddress]
|
|
5121
5121
|
});
|
|
@@ -5145,37 +5145,41 @@ async function getWalletsByOwner(params) {
|
|
|
5145
5145
|
// src/wallet/withdrawals.ts
|
|
5146
5146
|
async function getWithdrawalRequest(params) {
|
|
5147
5147
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
5148
|
-
const
|
|
5149
|
-
if (!
|
|
5150
|
-
throw new Error(`IATPWallet
|
|
5148
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5149
|
+
if (!walletAbi) {
|
|
5150
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5151
5151
|
}
|
|
5152
5152
|
const result = await publicClient.readContract({
|
|
5153
5153
|
address: walletAddress,
|
|
5154
|
-
abi:
|
|
5154
|
+
abi: walletAbi,
|
|
5155
5155
|
functionName: "getWithdrawalRequest",
|
|
5156
5156
|
args: [tokenAddress]
|
|
5157
5157
|
});
|
|
5158
|
-
|
|
5158
|
+
const [request, unlockTime] = result;
|
|
5159
|
+
if (request.amount === 0n) {
|
|
5159
5160
|
return null;
|
|
5160
5161
|
}
|
|
5161
|
-
return
|
|
5162
|
+
return {
|
|
5163
|
+
request,
|
|
5164
|
+
unlockTime
|
|
5165
|
+
};
|
|
5162
5166
|
}
|
|
5163
5167
|
async function requestWithdrawal(params) {
|
|
5164
5168
|
const { walletClient, publicClient, walletAddress, tokenAddress, amount, account, network = "sepolia" } = params;
|
|
5165
|
-
const
|
|
5166
|
-
if (!
|
|
5167
|
-
throw new Error(`IATPWallet
|
|
5169
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5170
|
+
if (!walletAbi) {
|
|
5171
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5168
5172
|
}
|
|
5169
5173
|
await publicClient.simulateContract({
|
|
5170
5174
|
account,
|
|
5171
5175
|
address: walletAddress,
|
|
5172
|
-
abi:
|
|
5176
|
+
abi: walletAbi,
|
|
5173
5177
|
functionName: "requestWithdrawal",
|
|
5174
5178
|
args: [tokenAddress, amount]
|
|
5175
5179
|
});
|
|
5176
5180
|
const estimatedGas = await publicClient.estimateContractGas({
|
|
5177
5181
|
address: walletAddress,
|
|
5178
|
-
abi:
|
|
5182
|
+
abi: walletAbi,
|
|
5179
5183
|
functionName: "requestWithdrawal",
|
|
5180
5184
|
args: [tokenAddress, amount],
|
|
5181
5185
|
account
|
|
@@ -5183,7 +5187,7 @@ async function requestWithdrawal(params) {
|
|
|
5183
5187
|
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5184
5188
|
const hash = await walletClient.writeContract({
|
|
5185
5189
|
address: walletAddress,
|
|
5186
|
-
abi:
|
|
5190
|
+
abi: walletAbi,
|
|
5187
5191
|
functionName: "requestWithdrawal",
|
|
5188
5192
|
args: [tokenAddress, amount],
|
|
5189
5193
|
account,
|
|
@@ -5194,20 +5198,20 @@ async function requestWithdrawal(params) {
|
|
|
5194
5198
|
}
|
|
5195
5199
|
async function executeWithdrawal(params) {
|
|
5196
5200
|
const { walletClient, publicClient, walletAddress, tokenAddress, account, network = "sepolia" } = params;
|
|
5197
|
-
const
|
|
5198
|
-
if (!
|
|
5199
|
-
throw new Error(`IATPWallet
|
|
5201
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5202
|
+
if (!walletAbi) {
|
|
5203
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5200
5204
|
}
|
|
5201
5205
|
await publicClient.simulateContract({
|
|
5202
5206
|
account,
|
|
5203
5207
|
address: walletAddress,
|
|
5204
|
-
abi:
|
|
5208
|
+
abi: walletAbi,
|
|
5205
5209
|
functionName: "executeWithdrawal",
|
|
5206
5210
|
args: [tokenAddress]
|
|
5207
5211
|
});
|
|
5208
5212
|
const estimatedGas = await publicClient.estimateContractGas({
|
|
5209
5213
|
address: walletAddress,
|
|
5210
|
-
abi:
|
|
5214
|
+
abi: walletAbi,
|
|
5211
5215
|
functionName: "executeWithdrawal",
|
|
5212
5216
|
args: [tokenAddress],
|
|
5213
5217
|
account
|
|
@@ -5215,7 +5219,7 @@ async function executeWithdrawal(params) {
|
|
|
5215
5219
|
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5216
5220
|
const hash = await walletClient.writeContract({
|
|
5217
5221
|
address: walletAddress,
|
|
5218
|
-
abi:
|
|
5222
|
+
abi: walletAbi,
|
|
5219
5223
|
functionName: "executeWithdrawal",
|
|
5220
5224
|
args: [tokenAddress],
|
|
5221
5225
|
account,
|
|
@@ -5308,7 +5312,7 @@ var D402Client = class {
|
|
|
5308
5312
|
*
|
|
5309
5313
|
* @param publicClient - Viem PublicClient
|
|
5310
5314
|
* @param tokenAddress - Token contract address
|
|
5311
|
-
* @returns Withdrawal request
|
|
5315
|
+
* @returns Withdrawal request details (request + unlockTime) or null if no request exists
|
|
5312
5316
|
*/
|
|
5313
5317
|
async getWithdrawalRequest(publicClient, tokenAddress) {
|
|
5314
5318
|
return getWithdrawalRequest({
|