@dcentralab/d402-client 0.2.6 → 0.3.0
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/README.md +58 -553
- package/dist/index.d.mts +452 -283
- package/dist/index.d.ts +452 -283
- package/dist/index.js +294 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +284 -70
- package/dist/index.mjs.map +1 -1
- package/package.json +10 -10
package/dist/index.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { http, createPublicClient, createWalletClient, decodeEventLog,
|
|
1
|
+
import { http, createPublicClient, createWalletClient, decodeEventLog, isAddress } from 'viem';
|
|
2
2
|
import { sepolia } from 'viem/chains';
|
|
3
3
|
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
@@ -11,10 +11,10 @@ var __export = (target, all) => {
|
|
|
11
11
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
// src/errors.ts
|
|
14
|
+
// src/core/errors.ts
|
|
15
15
|
var PaymentError, PaymentAmountExceededError, MissingRequestConfigError, PaymentAlreadyAttemptedError, UnsupportedSchemeError, PaymentVerificationError, Invalid402ResponseError, UnsupportedNetworkError;
|
|
16
16
|
var init_errors = __esm({
|
|
17
|
-
"src/errors.ts"() {
|
|
17
|
+
"src/core/errors.ts"() {
|
|
18
18
|
PaymentError = class _PaymentError extends Error {
|
|
19
19
|
constructor(message) {
|
|
20
20
|
super(message);
|
|
@@ -81,7 +81,7 @@ var init_errors = __esm({
|
|
|
81
81
|
}
|
|
82
82
|
});
|
|
83
83
|
|
|
84
|
-
// src/parser.ts
|
|
84
|
+
// src/payment/parser.ts
|
|
85
85
|
var parser_exports = {};
|
|
86
86
|
__export(parser_exports, {
|
|
87
87
|
parseAllPaymentRequirements: () => parseAllPaymentRequirements,
|
|
@@ -187,29 +187,18 @@ async function parseAllPaymentRequirements(response) {
|
|
|
187
187
|
return requirements;
|
|
188
188
|
}
|
|
189
189
|
var init_parser = __esm({
|
|
190
|
-
"src/parser.ts"() {
|
|
190
|
+
"src/payment/parser.ts"() {
|
|
191
191
|
init_errors();
|
|
192
192
|
}
|
|
193
193
|
});
|
|
194
194
|
|
|
195
|
-
// src/constants.ts
|
|
196
|
-
var
|
|
195
|
+
// src/core/constants.ts
|
|
196
|
+
var TOKEN_ADDRESSES, EIP712_TYPES;
|
|
197
197
|
var init_constants = __esm({
|
|
198
|
-
"src/constants.ts"() {
|
|
199
|
-
CHAIN_IDS = {
|
|
200
|
-
sepolia: 11155111
|
|
201
|
-
};
|
|
202
|
-
NETWORKS = {
|
|
203
|
-
sepolia: {
|
|
204
|
-
chainId: 11155111,
|
|
205
|
-
name: "Sepolia Testnet",
|
|
206
|
-
nativeCurrency: { name: "Sepolia Ether", symbol: "SEP", decimals: 18 }
|
|
207
|
-
}
|
|
208
|
-
};
|
|
198
|
+
"src/core/constants.ts"() {
|
|
209
199
|
TOKEN_ADDRESSES = {
|
|
210
200
|
sepolia: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
|
|
211
201
|
};
|
|
212
|
-
DEFAULT_VALIDITY_WINDOW_SECONDS = 300;
|
|
213
202
|
EIP712_TYPES = {
|
|
214
203
|
PullFundsForSettlement: [
|
|
215
204
|
{ name: "wallet", type: "address" },
|
|
@@ -223,7 +212,7 @@ var init_constants = __esm({
|
|
|
223
212
|
}
|
|
224
213
|
});
|
|
225
214
|
|
|
226
|
-
// src/utils.ts
|
|
215
|
+
// src/core/utils.ts
|
|
227
216
|
function parseMoney(amount, decimals) {
|
|
228
217
|
if (typeof amount === "bigint") {
|
|
229
218
|
return amount;
|
|
@@ -311,13 +300,13 @@ function decodePaymentResponse(header) {
|
|
|
311
300
|
}
|
|
312
301
|
}
|
|
313
302
|
var init_utils = __esm({
|
|
314
|
-
"src/utils.ts"() {
|
|
303
|
+
"src/core/utils.ts"() {
|
|
315
304
|
init_constants();
|
|
316
305
|
init_errors();
|
|
317
306
|
}
|
|
318
307
|
});
|
|
319
308
|
|
|
320
|
-
// src/signer.ts
|
|
309
|
+
// src/payment/signer.ts
|
|
321
310
|
var signer_exports = {};
|
|
322
311
|
__export(signer_exports, {
|
|
323
312
|
signD402Payment: () => signD402Payment
|
|
@@ -388,14 +377,13 @@ async function signD402Payment(params) {
|
|
|
388
377
|
return signedPayment;
|
|
389
378
|
}
|
|
390
379
|
var init_signer = __esm({
|
|
391
|
-
"src/signer.ts"() {
|
|
392
|
-
init_utils();
|
|
380
|
+
"src/payment/signer.ts"() {
|
|
393
381
|
init_utils();
|
|
394
382
|
init_constants();
|
|
395
383
|
}
|
|
396
384
|
});
|
|
397
385
|
|
|
398
|
-
// src/encoder.ts
|
|
386
|
+
// src/payment/encoder.ts
|
|
399
387
|
var encoder_exports = {};
|
|
400
388
|
__export(encoder_exports, {
|
|
401
389
|
decodePayment: () => decodePayment,
|
|
@@ -422,11 +410,11 @@ function decodePayment(encodedPayment) {
|
|
|
422
410
|
return JSON.parse(jsonString);
|
|
423
411
|
}
|
|
424
412
|
var init_encoder = __esm({
|
|
425
|
-
"src/encoder.ts"() {
|
|
413
|
+
"src/payment/encoder.ts"() {
|
|
426
414
|
}
|
|
427
415
|
});
|
|
428
416
|
|
|
429
|
-
// src/selector.ts
|
|
417
|
+
// src/payment/selector.ts
|
|
430
418
|
init_errors();
|
|
431
419
|
function selectPaymentRequirement(requirements, options = {}) {
|
|
432
420
|
const {
|
|
@@ -724,6 +712,25 @@ var sepolia_default = {
|
|
|
724
712
|
name: "ClientInitialized",
|
|
725
713
|
type: "event"
|
|
726
714
|
},
|
|
715
|
+
{
|
|
716
|
+
anonymous: false,
|
|
717
|
+
inputs: [
|
|
718
|
+
{
|
|
719
|
+
indexed: false,
|
|
720
|
+
internalType: "string",
|
|
721
|
+
name: "oldDescription",
|
|
722
|
+
type: "string"
|
|
723
|
+
},
|
|
724
|
+
{
|
|
725
|
+
indexed: false,
|
|
726
|
+
internalType: "string",
|
|
727
|
+
name: "newDescription",
|
|
728
|
+
type: "string"
|
|
729
|
+
}
|
|
730
|
+
],
|
|
731
|
+
name: "DescriptionUpdated",
|
|
732
|
+
type: "event"
|
|
733
|
+
},
|
|
727
734
|
{
|
|
728
735
|
anonymous: false,
|
|
729
736
|
inputs: [],
|
|
@@ -793,6 +800,25 @@ var sepolia_default = {
|
|
|
793
800
|
name: "Initialized",
|
|
794
801
|
type: "event"
|
|
795
802
|
},
|
|
803
|
+
{
|
|
804
|
+
anonymous: false,
|
|
805
|
+
inputs: [
|
|
806
|
+
{
|
|
807
|
+
indexed: false,
|
|
808
|
+
internalType: "string",
|
|
809
|
+
name: "oldName",
|
|
810
|
+
type: "string"
|
|
811
|
+
},
|
|
812
|
+
{
|
|
813
|
+
indexed: false,
|
|
814
|
+
internalType: "string",
|
|
815
|
+
name: "newName",
|
|
816
|
+
type: "string"
|
|
817
|
+
}
|
|
818
|
+
],
|
|
819
|
+
name: "NameUpdated",
|
|
820
|
+
type: "event"
|
|
821
|
+
},
|
|
796
822
|
{
|
|
797
823
|
anonymous: false,
|
|
798
824
|
inputs: [
|
|
@@ -838,6 +864,25 @@ var sepolia_default = {
|
|
|
838
864
|
name: "Upgraded",
|
|
839
865
|
type: "event"
|
|
840
866
|
},
|
|
867
|
+
{
|
|
868
|
+
anonymous: false,
|
|
869
|
+
inputs: [
|
|
870
|
+
{
|
|
871
|
+
indexed: true,
|
|
872
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
873
|
+
name: "oldWalletType",
|
|
874
|
+
type: "uint8"
|
|
875
|
+
},
|
|
876
|
+
{
|
|
877
|
+
indexed: true,
|
|
878
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
879
|
+
name: "newWalletType",
|
|
880
|
+
type: "uint8"
|
|
881
|
+
}
|
|
882
|
+
],
|
|
883
|
+
name: "WalletTypeUpdated",
|
|
884
|
+
type: "event"
|
|
885
|
+
},
|
|
841
886
|
{
|
|
842
887
|
anonymous: false,
|
|
843
888
|
inputs: [
|
|
@@ -1022,6 +1067,19 @@ var sepolia_default = {
|
|
|
1022
1067
|
stateMutability: "nonpayable",
|
|
1023
1068
|
type: "function"
|
|
1024
1069
|
},
|
|
1070
|
+
{
|
|
1071
|
+
inputs: [],
|
|
1072
|
+
name: "description",
|
|
1073
|
+
outputs: [
|
|
1074
|
+
{
|
|
1075
|
+
internalType: "string",
|
|
1076
|
+
name: "",
|
|
1077
|
+
type: "string"
|
|
1078
|
+
}
|
|
1079
|
+
],
|
|
1080
|
+
stateMutability: "view",
|
|
1081
|
+
type: "function"
|
|
1082
|
+
},
|
|
1025
1083
|
{
|
|
1026
1084
|
inputs: [],
|
|
1027
1085
|
name: "eip712Domain",
|
|
@@ -1183,6 +1241,21 @@ var sepolia_default = {
|
|
|
1183
1241
|
internalType: "address",
|
|
1184
1242
|
name: "_settlementLayer",
|
|
1185
1243
|
type: "address"
|
|
1244
|
+
},
|
|
1245
|
+
{
|
|
1246
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1247
|
+
name: "_walletType",
|
|
1248
|
+
type: "uint8"
|
|
1249
|
+
},
|
|
1250
|
+
{
|
|
1251
|
+
internalType: "string",
|
|
1252
|
+
name: "_name",
|
|
1253
|
+
type: "string"
|
|
1254
|
+
},
|
|
1255
|
+
{
|
|
1256
|
+
internalType: "string",
|
|
1257
|
+
name: "_description",
|
|
1258
|
+
type: "string"
|
|
1186
1259
|
}
|
|
1187
1260
|
],
|
|
1188
1261
|
name: "initialize",
|
|
@@ -1253,6 +1326,19 @@ var sepolia_default = {
|
|
|
1253
1326
|
stateMutability: "view",
|
|
1254
1327
|
type: "function"
|
|
1255
1328
|
},
|
|
1329
|
+
{
|
|
1330
|
+
inputs: [],
|
|
1331
|
+
name: "name",
|
|
1332
|
+
outputs: [
|
|
1333
|
+
{
|
|
1334
|
+
internalType: "string",
|
|
1335
|
+
name: "",
|
|
1336
|
+
type: "string"
|
|
1337
|
+
}
|
|
1338
|
+
],
|
|
1339
|
+
stateMutability: "view",
|
|
1340
|
+
type: "function"
|
|
1341
|
+
},
|
|
1256
1342
|
{
|
|
1257
1343
|
inputs: [],
|
|
1258
1344
|
name: "operatorAddress",
|
|
@@ -1374,6 +1460,29 @@ var sepolia_default = {
|
|
|
1374
1460
|
stateMutability: "view",
|
|
1375
1461
|
type: "function"
|
|
1376
1462
|
},
|
|
1463
|
+
{
|
|
1464
|
+
inputs: [
|
|
1465
|
+
{
|
|
1466
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1467
|
+
name: "_newWalletType",
|
|
1468
|
+
type: "uint8"
|
|
1469
|
+
},
|
|
1470
|
+
{
|
|
1471
|
+
internalType: "string",
|
|
1472
|
+
name: "_newName",
|
|
1473
|
+
type: "string"
|
|
1474
|
+
},
|
|
1475
|
+
{
|
|
1476
|
+
internalType: "string",
|
|
1477
|
+
name: "_newDescription",
|
|
1478
|
+
type: "string"
|
|
1479
|
+
}
|
|
1480
|
+
],
|
|
1481
|
+
name: "updateMetadata",
|
|
1482
|
+
outputs: [],
|
|
1483
|
+
stateMutability: "nonpayable",
|
|
1484
|
+
type: "function"
|
|
1485
|
+
},
|
|
1377
1486
|
{
|
|
1378
1487
|
inputs: [
|
|
1379
1488
|
{
|
|
@@ -1487,6 +1596,19 @@ var sepolia_default = {
|
|
|
1487
1596
|
stateMutability: "view",
|
|
1488
1597
|
type: "function"
|
|
1489
1598
|
},
|
|
1599
|
+
{
|
|
1600
|
+
inputs: [],
|
|
1601
|
+
name: "walletType",
|
|
1602
|
+
outputs: [
|
|
1603
|
+
{
|
|
1604
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1605
|
+
name: "",
|
|
1606
|
+
type: "uint8"
|
|
1607
|
+
}
|
|
1608
|
+
],
|
|
1609
|
+
stateMutability: "view",
|
|
1610
|
+
type: "function"
|
|
1611
|
+
},
|
|
1490
1612
|
{
|
|
1491
1613
|
inputs: [
|
|
1492
1614
|
{
|
|
@@ -4341,6 +4463,64 @@ var sepolia_default = {
|
|
|
4341
4463
|
type: "address"
|
|
4342
4464
|
}
|
|
4343
4465
|
],
|
|
4466
|
+
name: "createClientWallet",
|
|
4467
|
+
outputs: [
|
|
4468
|
+
{
|
|
4469
|
+
internalType: "address",
|
|
4470
|
+
name: "wallet",
|
|
4471
|
+
type: "address"
|
|
4472
|
+
}
|
|
4473
|
+
],
|
|
4474
|
+
stateMutability: "nonpayable",
|
|
4475
|
+
type: "function"
|
|
4476
|
+
},
|
|
4477
|
+
{
|
|
4478
|
+
inputs: [
|
|
4479
|
+
{
|
|
4480
|
+
internalType: "address",
|
|
4481
|
+
name: "_owner",
|
|
4482
|
+
type: "address"
|
|
4483
|
+
},
|
|
4484
|
+
{
|
|
4485
|
+
internalType: "address",
|
|
4486
|
+
name: "_operatorAddress",
|
|
4487
|
+
type: "address"
|
|
4488
|
+
}
|
|
4489
|
+
],
|
|
4490
|
+
name: "createClientWalletFor",
|
|
4491
|
+
outputs: [
|
|
4492
|
+
{
|
|
4493
|
+
internalType: "address",
|
|
4494
|
+
name: "wallet",
|
|
4495
|
+
type: "address"
|
|
4496
|
+
}
|
|
4497
|
+
],
|
|
4498
|
+
stateMutability: "nonpayable",
|
|
4499
|
+
type: "function"
|
|
4500
|
+
},
|
|
4501
|
+
{
|
|
4502
|
+
inputs: [
|
|
4503
|
+
{
|
|
4504
|
+
internalType: "address",
|
|
4505
|
+
name: "_operatorAddress",
|
|
4506
|
+
type: "address"
|
|
4507
|
+
},
|
|
4508
|
+
{
|
|
4509
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
4510
|
+
name: "_walletType",
|
|
4511
|
+
type: "uint8"
|
|
4512
|
+
},
|
|
4513
|
+
{
|
|
4514
|
+
internalType: "string",
|
|
4515
|
+
name: "_name",
|
|
4516
|
+
type: "string"
|
|
4517
|
+
},
|
|
4518
|
+
{
|
|
4519
|
+
internalType: "string",
|
|
4520
|
+
name: "_description",
|
|
4521
|
+
type: "string"
|
|
4522
|
+
}
|
|
4523
|
+
],
|
|
4344
4524
|
name: "createWallet",
|
|
4345
4525
|
outputs: [
|
|
4346
4526
|
{
|
|
@@ -4363,6 +4543,21 @@ var sepolia_default = {
|
|
|
4363
4543
|
internalType: "address",
|
|
4364
4544
|
name: "_operatorAddress",
|
|
4365
4545
|
type: "address"
|
|
4546
|
+
},
|
|
4547
|
+
{
|
|
4548
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
4549
|
+
name: "_walletType",
|
|
4550
|
+
type: "uint8"
|
|
4551
|
+
},
|
|
4552
|
+
{
|
|
4553
|
+
internalType: "string",
|
|
4554
|
+
name: "_name",
|
|
4555
|
+
type: "string"
|
|
4556
|
+
},
|
|
4557
|
+
{
|
|
4558
|
+
internalType: "string",
|
|
4559
|
+
name: "_description",
|
|
4560
|
+
type: "string"
|
|
4366
4561
|
}
|
|
4367
4562
|
],
|
|
4368
4563
|
name: "createWalletFor",
|
|
@@ -4799,14 +4994,21 @@ var implementations_default = {
|
|
|
4799
4994
|
sepolia: {
|
|
4800
4995
|
Congress: "0x94Fc9eddBd1779542b78eb92F0569762603876e2",
|
|
4801
4996
|
TraiaCongressMembersRegistry: "0x3B685403b195f16D103b42FCf56F848A278d6049",
|
|
4802
|
-
IATPWalletImplementation: "
|
|
4997
|
+
IATPWalletImplementation: "0x4f9f0E1cD21f7122417A2A13b03c1BE84b7CB37E",
|
|
4803
4998
|
RoleManagerImplementation: "0x585AD85FCFBec3B1503E50b46407bF65d4006560",
|
|
4804
4999
|
IATPSettlementLayerImplementation: "0x0fDd39d323EE3538c800d4A13730eecE3F0bA975",
|
|
4805
|
-
IATPWalletFactoryImplementation: "
|
|
5000
|
+
IATPWalletFactoryImplementation: "0x4AC08c53C7ce1244a458D49A4101C3DC664e2D37"
|
|
4806
5001
|
}
|
|
4807
5002
|
};
|
|
4808
5003
|
|
|
4809
|
-
// src/contracts.ts
|
|
5004
|
+
// src/contracts/index.ts
|
|
5005
|
+
var ContractName = /* @__PURE__ */ ((ContractName2) => {
|
|
5006
|
+
ContractName2["IATP_WALLET"] = "IATPWallet";
|
|
5007
|
+
ContractName2["IATP_WALLET_FACTORY"] = "IATPWalletFactory";
|
|
5008
|
+
ContractName2["IATP_SETTLEMENT_LAYER"] = "IATPSettlementLayer";
|
|
5009
|
+
ContractName2["ROLE_MANAGER"] = "RoleManager";
|
|
5010
|
+
return ContractName2;
|
|
5011
|
+
})(ContractName || {});
|
|
4810
5012
|
var ABIS = {
|
|
4811
5013
|
sepolia: sepolia_default.sepolia || {}
|
|
4812
5014
|
};
|
|
@@ -4836,7 +5038,7 @@ function getContractConfig(contractName, network = "sepolia") {
|
|
|
4836
5038
|
return { address, abi };
|
|
4837
5039
|
}
|
|
4838
5040
|
|
|
4839
|
-
// src/wallet.ts
|
|
5041
|
+
// src/wallet/creation.ts
|
|
4840
5042
|
async function createIATPWallet(params) {
|
|
4841
5043
|
const { ownerAccount, network = "sepolia", rpcUrl } = params;
|
|
4842
5044
|
const factoryConfig = getContractConfig("IATPWalletFactory" /* IATP_WALLET_FACTORY */, network);
|
|
@@ -4864,7 +5066,7 @@ async function createIATPWallet(params) {
|
|
|
4864
5066
|
address: factoryConfig.address,
|
|
4865
5067
|
abi: factoryConfig.abi,
|
|
4866
5068
|
functionName: "createWallet",
|
|
4867
|
-
args: [operatorAddress]
|
|
5069
|
+
args: [operatorAddress, 0, "", ""]
|
|
4868
5070
|
});
|
|
4869
5071
|
const hash = await walletClient.writeContract(request);
|
|
4870
5072
|
const receipt = await publicClient.waitForTransactionReceipt({
|
|
@@ -4924,6 +5126,8 @@ async function getWalletsByOwner(params) {
|
|
|
4924
5126
|
});
|
|
4925
5127
|
return wallets;
|
|
4926
5128
|
}
|
|
5129
|
+
|
|
5130
|
+
// src/wallet/queries.ts
|
|
4927
5131
|
async function getAvailableBalance(params) {
|
|
4928
5132
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
4929
5133
|
const walletConfig = getContractConfig("IATPWallet" /* IATP_WALLET */, network);
|
|
@@ -4938,6 +5142,8 @@ async function getAvailableBalance(params) {
|
|
|
4938
5142
|
});
|
|
4939
5143
|
return balance;
|
|
4940
5144
|
}
|
|
5145
|
+
|
|
5146
|
+
// src/wallet/withdrawals.ts
|
|
4941
5147
|
async function getWithdrawalRequest(params) {
|
|
4942
5148
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
4943
5149
|
const walletConfig = getContractConfig("IATPWallet" /* IATP_WALLET */, network);
|
|
@@ -4961,26 +5167,27 @@ async function requestWithdrawal(params) {
|
|
|
4961
5167
|
if (!walletConfig) {
|
|
4962
5168
|
throw new Error(`IATPWallet contract not found for network: ${network}`);
|
|
4963
5169
|
}
|
|
4964
|
-
|
|
5170
|
+
await publicClient.simulateContract({
|
|
5171
|
+
account,
|
|
5172
|
+
address: walletAddress,
|
|
4965
5173
|
abi: walletConfig.abi,
|
|
4966
5174
|
functionName: "requestWithdrawal",
|
|
4967
5175
|
args: [tokenAddress, amount]
|
|
4968
5176
|
});
|
|
4969
|
-
const estimatedGas = await publicClient.
|
|
4970
|
-
account: account.address,
|
|
4971
|
-
to: walletAddress,
|
|
4972
|
-
data
|
|
4973
|
-
});
|
|
4974
|
-
const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
|
|
4975
|
-
const { request } = await publicClient.simulateContract({
|
|
4976
|
-
account,
|
|
5177
|
+
const estimatedGas = await publicClient.estimateContractGas({
|
|
4977
5178
|
address: walletAddress,
|
|
4978
5179
|
abi: walletConfig.abi,
|
|
4979
5180
|
functionName: "requestWithdrawal",
|
|
4980
|
-
args: [tokenAddress, amount]
|
|
5181
|
+
args: [tokenAddress, amount],
|
|
5182
|
+
account
|
|
4981
5183
|
});
|
|
5184
|
+
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
4982
5185
|
const hash = await walletClient.writeContract({
|
|
4983
|
-
|
|
5186
|
+
address: walletAddress,
|
|
5187
|
+
abi: walletConfig.abi,
|
|
5188
|
+
functionName: "requestWithdrawal",
|
|
5189
|
+
args: [tokenAddress, amount],
|
|
5190
|
+
account,
|
|
4984
5191
|
gas: gasLimit
|
|
4985
5192
|
});
|
|
4986
5193
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
@@ -4992,33 +5199,34 @@ async function executeWithdrawal(params) {
|
|
|
4992
5199
|
if (!walletConfig) {
|
|
4993
5200
|
throw new Error(`IATPWallet contract not found for network: ${network}`);
|
|
4994
5201
|
}
|
|
4995
|
-
|
|
5202
|
+
await publicClient.simulateContract({
|
|
5203
|
+
account,
|
|
5204
|
+
address: walletAddress,
|
|
4996
5205
|
abi: walletConfig.abi,
|
|
4997
5206
|
functionName: "executeWithdrawal",
|
|
4998
5207
|
args: [tokenAddress]
|
|
4999
5208
|
});
|
|
5000
|
-
const estimatedGas = await publicClient.
|
|
5001
|
-
account: account.address,
|
|
5002
|
-
to: walletAddress,
|
|
5003
|
-
data
|
|
5004
|
-
});
|
|
5005
|
-
const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
|
|
5006
|
-
const { request } = await publicClient.simulateContract({
|
|
5007
|
-
account,
|
|
5209
|
+
const estimatedGas = await publicClient.estimateContractGas({
|
|
5008
5210
|
address: walletAddress,
|
|
5009
5211
|
abi: walletConfig.abi,
|
|
5010
5212
|
functionName: "executeWithdrawal",
|
|
5011
|
-
args: [tokenAddress]
|
|
5213
|
+
args: [tokenAddress],
|
|
5214
|
+
account
|
|
5012
5215
|
});
|
|
5216
|
+
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5013
5217
|
const hash = await walletClient.writeContract({
|
|
5014
|
-
|
|
5218
|
+
address: walletAddress,
|
|
5219
|
+
abi: walletConfig.abi,
|
|
5220
|
+
functionName: "executeWithdrawal",
|
|
5221
|
+
args: [tokenAddress],
|
|
5222
|
+
account,
|
|
5015
5223
|
gas: gasLimit
|
|
5016
5224
|
});
|
|
5017
5225
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
5018
5226
|
return hash;
|
|
5019
5227
|
}
|
|
5020
5228
|
|
|
5021
|
-
// src/client.ts
|
|
5229
|
+
// src/client/D402Client.ts
|
|
5022
5230
|
var D402Client = class {
|
|
5023
5231
|
/**
|
|
5024
5232
|
* Create a new D402 Client.
|
|
@@ -5211,9 +5419,8 @@ var D402Client = class {
|
|
|
5211
5419
|
init_signer();
|
|
5212
5420
|
init_parser();
|
|
5213
5421
|
init_encoder();
|
|
5214
|
-
|
|
5215
|
-
|
|
5216
|
-
init_constants();
|
|
5422
|
+
|
|
5423
|
+
// src/settlement/queries.ts
|
|
5217
5424
|
async function getLockedBalanceForProvider(params) {
|
|
5218
5425
|
const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
|
|
5219
5426
|
const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
|
|
@@ -5242,6 +5449,8 @@ async function getUnlockedBalanceForProvider(params) {
|
|
|
5242
5449
|
});
|
|
5243
5450
|
return balance;
|
|
5244
5451
|
}
|
|
5452
|
+
|
|
5453
|
+
// src/settlement/operations.ts
|
|
5245
5454
|
async function withdrawAllAvailableEpochs(params) {
|
|
5246
5455
|
const { walletClient, publicClient, tokenAddress, network = "sepolia" } = params;
|
|
5247
5456
|
if (!walletClient?.account) {
|
|
@@ -5252,32 +5461,37 @@ async function withdrawAllAvailableEpochs(params) {
|
|
|
5252
5461
|
if (!settlementConfig) {
|
|
5253
5462
|
throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
|
|
5254
5463
|
}
|
|
5255
|
-
|
|
5464
|
+
await publicClient.simulateContract({
|
|
5465
|
+
account,
|
|
5466
|
+
address: settlementConfig.address,
|
|
5256
5467
|
abi: settlementConfig.abi,
|
|
5257
5468
|
functionName: "withdrawAllAvailableEpochs",
|
|
5258
5469
|
args: [tokenAddress]
|
|
5259
5470
|
});
|
|
5260
|
-
const estimatedGas = await publicClient.
|
|
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,
|
|
5471
|
+
const estimatedGas = await publicClient.estimateContractGas({
|
|
5268
5472
|
address: settlementConfig.address,
|
|
5269
5473
|
abi: settlementConfig.abi,
|
|
5270
5474
|
functionName: "withdrawAllAvailableEpochs",
|
|
5271
|
-
args: [tokenAddress]
|
|
5475
|
+
args: [tokenAddress],
|
|
5476
|
+
account
|
|
5272
5477
|
});
|
|
5478
|
+
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5273
5479
|
const hash = await walletClient.writeContract({
|
|
5274
|
-
|
|
5480
|
+
address: settlementConfig.address,
|
|
5481
|
+
abi: settlementConfig.abi,
|
|
5482
|
+
functionName: "withdrawAllAvailableEpochs",
|
|
5483
|
+
args: [tokenAddress],
|
|
5484
|
+
account,
|
|
5275
5485
|
gas: gasLimit
|
|
5276
5486
|
});
|
|
5277
5487
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
5278
5488
|
return hash;
|
|
5279
5489
|
}
|
|
5280
5490
|
|
|
5281
|
-
|
|
5491
|
+
// src/index.ts
|
|
5492
|
+
init_utils();
|
|
5493
|
+
init_errors();
|
|
5494
|
+
|
|
5495
|
+
export { ContractName, D402Client, Invalid402ResponseError, MissingRequestConfigError, PaymentAlreadyAttemptedError, PaymentAmountExceededError, PaymentError, PaymentVerificationError, UnsupportedNetworkError, UnsupportedSchemeError, 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 };
|
|
5282
5496
|
//# sourceMappingURL=index.mjs.map
|
|
5283
5497
|
//# sourceMappingURL=index.mjs.map
|