@dcentralab/d402-client 0.3.3 → 0.3.5
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 +22 -0
- package/dist/index.d.mts +32 -16
- package/dist/index.d.ts +32 -16
- package/dist/index.js +41 -30
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -30
- package/dist/index.mjs.map +1 -1
- package/package.json +11 -11
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
|
@@ -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
|
*
|
|
@@ -425,7 +423,7 @@ declare class D402Client {
|
|
|
425
423
|
declare function signD402Payment(params: {
|
|
426
424
|
operatorAccount: Account;
|
|
427
425
|
paymentRequirement: PaymentRequirement;
|
|
428
|
-
iatpWalletAddress
|
|
426
|
+
iatpWalletAddress: `0x${string}`;
|
|
429
427
|
requestPath?: string;
|
|
430
428
|
d402Version?: number;
|
|
431
429
|
}): Promise<SignedPayment>;
|
|
@@ -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
|
*
|
|
@@ -425,7 +423,7 @@ declare class D402Client {
|
|
|
425
423
|
declare function signD402Payment(params: {
|
|
426
424
|
operatorAccount: Account;
|
|
427
425
|
paymentRequirement: PaymentRequirement;
|
|
428
|
-
iatpWalletAddress
|
|
426
|
+
iatpWalletAddress: `0x${string}`;
|
|
429
427
|
requestPath?: string;
|
|
430
428
|
d402Version?: number;
|
|
431
429
|
}): Promise<SignedPayment>;
|
|
@@ -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
|
@@ -304,7 +304,6 @@ async function signD402Payment(params) {
|
|
|
304
304
|
requestPath,
|
|
305
305
|
d402Version = 1
|
|
306
306
|
} = params;
|
|
307
|
-
const consumerWallet = iatpWalletAddress || operatorAccount.address;
|
|
308
307
|
let finalRequestPath = requestPath || paymentRequirement.resource || "/mcp";
|
|
309
308
|
if (!finalRequestPath || finalRequestPath.trim() === "") {
|
|
310
309
|
finalRequestPath = "/mcp";
|
|
@@ -321,10 +320,10 @@ async function signD402Payment(params) {
|
|
|
321
320
|
name: walletName,
|
|
322
321
|
version: walletVersion,
|
|
323
322
|
chainId,
|
|
324
|
-
verifyingContract:
|
|
323
|
+
verifyingContract: iatpWalletAddress
|
|
325
324
|
};
|
|
326
325
|
const message = {
|
|
327
|
-
wallet:
|
|
326
|
+
wallet: iatpWalletAddress,
|
|
328
327
|
provider: paymentRequirement.payTo,
|
|
329
328
|
token: paymentRequirement.asset,
|
|
330
329
|
amount: BigInt(paymentRequirement.maxAmountRequired),
|
|
@@ -349,7 +348,7 @@ async function signD402Payment(params) {
|
|
|
349
348
|
payload: {
|
|
350
349
|
signature,
|
|
351
350
|
authorization: {
|
|
352
|
-
from:
|
|
351
|
+
from: iatpWalletAddress,
|
|
353
352
|
to: paymentRequirement.payTo,
|
|
354
353
|
value: paymentRequirement.maxAmountRequired,
|
|
355
354
|
validAfter,
|
|
@@ -5109,13 +5108,13 @@ async function createIATPWallet(params) {
|
|
|
5109
5108
|
}
|
|
5110
5109
|
async function getAvailableBalance(params) {
|
|
5111
5110
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
5112
|
-
const
|
|
5113
|
-
if (!
|
|
5114
|
-
throw new Error(`IATPWallet
|
|
5111
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5112
|
+
if (!walletAbi) {
|
|
5113
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5115
5114
|
}
|
|
5116
5115
|
const balance = await publicClient.readContract({
|
|
5117
5116
|
address: walletAddress,
|
|
5118
|
-
abi:
|
|
5117
|
+
abi: walletAbi,
|
|
5119
5118
|
functionName: "getAvailableBalance",
|
|
5120
5119
|
args: [tokenAddress]
|
|
5121
5120
|
});
|
|
@@ -5145,37 +5144,41 @@ async function getWalletsByOwner(params) {
|
|
|
5145
5144
|
// src/wallet/withdrawals.ts
|
|
5146
5145
|
async function getWithdrawalRequest(params) {
|
|
5147
5146
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
5148
|
-
const
|
|
5149
|
-
if (!
|
|
5150
|
-
throw new Error(`IATPWallet
|
|
5147
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5148
|
+
if (!walletAbi) {
|
|
5149
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5151
5150
|
}
|
|
5152
5151
|
const result = await publicClient.readContract({
|
|
5153
5152
|
address: walletAddress,
|
|
5154
|
-
abi:
|
|
5153
|
+
abi: walletAbi,
|
|
5155
5154
|
functionName: "getWithdrawalRequest",
|
|
5156
5155
|
args: [tokenAddress]
|
|
5157
5156
|
});
|
|
5158
|
-
|
|
5157
|
+
const [request, unlockTime] = result;
|
|
5158
|
+
if (request.amount === 0n) {
|
|
5159
5159
|
return null;
|
|
5160
5160
|
}
|
|
5161
|
-
return
|
|
5161
|
+
return {
|
|
5162
|
+
request,
|
|
5163
|
+
unlockTime
|
|
5164
|
+
};
|
|
5162
5165
|
}
|
|
5163
5166
|
async function requestWithdrawal(params) {
|
|
5164
5167
|
const { walletClient, publicClient, walletAddress, tokenAddress, amount, account, network = "sepolia" } = params;
|
|
5165
|
-
const
|
|
5166
|
-
if (!
|
|
5167
|
-
throw new Error(`IATPWallet
|
|
5168
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5169
|
+
if (!walletAbi) {
|
|
5170
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5168
5171
|
}
|
|
5169
5172
|
await publicClient.simulateContract({
|
|
5170
5173
|
account,
|
|
5171
5174
|
address: walletAddress,
|
|
5172
|
-
abi:
|
|
5175
|
+
abi: walletAbi,
|
|
5173
5176
|
functionName: "requestWithdrawal",
|
|
5174
5177
|
args: [tokenAddress, amount]
|
|
5175
5178
|
});
|
|
5176
5179
|
const estimatedGas = await publicClient.estimateContractGas({
|
|
5177
5180
|
address: walletAddress,
|
|
5178
|
-
abi:
|
|
5181
|
+
abi: walletAbi,
|
|
5179
5182
|
functionName: "requestWithdrawal",
|
|
5180
5183
|
args: [tokenAddress, amount],
|
|
5181
5184
|
account
|
|
@@ -5183,7 +5186,7 @@ async function requestWithdrawal(params) {
|
|
|
5183
5186
|
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5184
5187
|
const hash = await walletClient.writeContract({
|
|
5185
5188
|
address: walletAddress,
|
|
5186
|
-
abi:
|
|
5189
|
+
abi: walletAbi,
|
|
5187
5190
|
functionName: "requestWithdrawal",
|
|
5188
5191
|
args: [tokenAddress, amount],
|
|
5189
5192
|
account,
|
|
@@ -5194,20 +5197,20 @@ async function requestWithdrawal(params) {
|
|
|
5194
5197
|
}
|
|
5195
5198
|
async function executeWithdrawal(params) {
|
|
5196
5199
|
const { walletClient, publicClient, walletAddress, tokenAddress, account, network = "sepolia" } = params;
|
|
5197
|
-
const
|
|
5198
|
-
if (!
|
|
5199
|
-
throw new Error(`IATPWallet
|
|
5200
|
+
const walletAbi = getContractAbi("IATPWallet" /* IATP_WALLET */, network);
|
|
5201
|
+
if (!walletAbi) {
|
|
5202
|
+
throw new Error(`IATPWallet ABI not found for network: ${network}`);
|
|
5200
5203
|
}
|
|
5201
5204
|
await publicClient.simulateContract({
|
|
5202
5205
|
account,
|
|
5203
5206
|
address: walletAddress,
|
|
5204
|
-
abi:
|
|
5207
|
+
abi: walletAbi,
|
|
5205
5208
|
functionName: "executeWithdrawal",
|
|
5206
5209
|
args: [tokenAddress]
|
|
5207
5210
|
});
|
|
5208
5211
|
const estimatedGas = await publicClient.estimateContractGas({
|
|
5209
5212
|
address: walletAddress,
|
|
5210
|
-
abi:
|
|
5213
|
+
abi: walletAbi,
|
|
5211
5214
|
functionName: "executeWithdrawal",
|
|
5212
5215
|
args: [tokenAddress],
|
|
5213
5216
|
account
|
|
@@ -5215,7 +5218,7 @@ async function executeWithdrawal(params) {
|
|
|
5215
5218
|
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5216
5219
|
const hash = await walletClient.writeContract({
|
|
5217
5220
|
address: walletAddress,
|
|
5218
|
-
abi:
|
|
5221
|
+
abi: walletAbi,
|
|
5219
5222
|
functionName: "executeWithdrawal",
|
|
5220
5223
|
args: [tokenAddress],
|
|
5221
5224
|
account,
|
|
@@ -5308,7 +5311,7 @@ var D402Client = class {
|
|
|
5308
5311
|
*
|
|
5309
5312
|
* @param publicClient - Viem PublicClient
|
|
5310
5313
|
* @param tokenAddress - Token contract address
|
|
5311
|
-
* @returns Withdrawal request
|
|
5314
|
+
* @returns Withdrawal request details (request + unlockTime) or null if no request exists
|
|
5312
5315
|
*/
|
|
5313
5316
|
async getWithdrawalRequest(publicClient, tokenAddress) {
|
|
5314
5317
|
return getWithdrawalRequest({
|
|
@@ -5386,7 +5389,15 @@ var D402Client = class {
|
|
|
5386
5389
|
const { parseAllPaymentRequirements: parseAllPaymentRequirements2 } = await Promise.resolve().then(() => (init_parser(), parser_exports));
|
|
5387
5390
|
const { signD402Payment: signD402Payment2 } = await Promise.resolve().then(() => (init_signer(), signer_exports));
|
|
5388
5391
|
const { encodePayment: encodePayment2 } = await Promise.resolve().then(() => (init_encoder(), encoder_exports));
|
|
5389
|
-
|
|
5392
|
+
const enhancedInit = {
|
|
5393
|
+
...init,
|
|
5394
|
+
headers: {
|
|
5395
|
+
...init?.headers,
|
|
5396
|
+
// Preserve existing Accept header or set default for MCP compatibility
|
|
5397
|
+
"Accept": init?.headers?.["Accept"] || "application/json, text/event-stream"
|
|
5398
|
+
}
|
|
5399
|
+
};
|
|
5400
|
+
let response = await fetch(url, enhancedInit);
|
|
5390
5401
|
if (response.status !== 402) {
|
|
5391
5402
|
return response;
|
|
5392
5403
|
}
|
|
@@ -5400,9 +5411,9 @@ var D402Client = class {
|
|
|
5400
5411
|
});
|
|
5401
5412
|
const paymentHeader = encodePayment2(signedPayment);
|
|
5402
5413
|
response = await fetch(url, {
|
|
5403
|
-
...
|
|
5414
|
+
...enhancedInit,
|
|
5404
5415
|
headers: {
|
|
5405
|
-
...
|
|
5416
|
+
...enhancedInit.headers,
|
|
5406
5417
|
"X-Payment": paymentHeader,
|
|
5407
5418
|
"Access-Control-Expose-Headers": "X-Payment-Response"
|
|
5408
5419
|
}
|