@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.js
CHANGED
|
@@ -13,10 +13,10 @@ var __export = (target, all) => {
|
|
|
13
13
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
// src/errors.ts
|
|
16
|
+
// src/core/errors.ts
|
|
17
17
|
exports.PaymentError = void 0; exports.PaymentAmountExceededError = void 0; exports.MissingRequestConfigError = void 0; exports.PaymentAlreadyAttemptedError = void 0; exports.UnsupportedSchemeError = void 0; exports.PaymentVerificationError = void 0; exports.Invalid402ResponseError = void 0; exports.UnsupportedNetworkError = void 0;
|
|
18
18
|
var init_errors = __esm({
|
|
19
|
-
"src/errors.ts"() {
|
|
19
|
+
"src/core/errors.ts"() {
|
|
20
20
|
exports.PaymentError = class _PaymentError extends Error {
|
|
21
21
|
constructor(message) {
|
|
22
22
|
super(message);
|
|
@@ -83,7 +83,7 @@ var init_errors = __esm({
|
|
|
83
83
|
}
|
|
84
84
|
});
|
|
85
85
|
|
|
86
|
-
// src/parser.ts
|
|
86
|
+
// src/payment/parser.ts
|
|
87
87
|
var parser_exports = {};
|
|
88
88
|
__export(parser_exports, {
|
|
89
89
|
parseAllPaymentRequirements: () => parseAllPaymentRequirements,
|
|
@@ -189,30 +189,19 @@ async function parseAllPaymentRequirements(response) {
|
|
|
189
189
|
return requirements;
|
|
190
190
|
}
|
|
191
191
|
var init_parser = __esm({
|
|
192
|
-
"src/parser.ts"() {
|
|
192
|
+
"src/payment/parser.ts"() {
|
|
193
193
|
init_errors();
|
|
194
194
|
}
|
|
195
195
|
});
|
|
196
196
|
|
|
197
|
-
// src/constants.ts
|
|
198
|
-
|
|
197
|
+
// src/core/constants.ts
|
|
198
|
+
var TOKEN_ADDRESSES, EIP712_TYPES;
|
|
199
199
|
var init_constants = __esm({
|
|
200
|
-
"src/constants.ts"() {
|
|
201
|
-
|
|
202
|
-
sepolia: 11155111
|
|
203
|
-
};
|
|
204
|
-
exports.NETWORKS = {
|
|
205
|
-
sepolia: {
|
|
206
|
-
chainId: 11155111,
|
|
207
|
-
name: "Sepolia Testnet",
|
|
208
|
-
nativeCurrency: { name: "Sepolia Ether", symbol: "SEP", decimals: 18 }
|
|
209
|
-
}
|
|
210
|
-
};
|
|
211
|
-
exports.TOKEN_ADDRESSES = {
|
|
200
|
+
"src/core/constants.ts"() {
|
|
201
|
+
TOKEN_ADDRESSES = {
|
|
212
202
|
sepolia: "0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"
|
|
213
203
|
};
|
|
214
|
-
|
|
215
|
-
exports.EIP712_TYPES = {
|
|
204
|
+
EIP712_TYPES = {
|
|
216
205
|
PullFundsForSettlement: [
|
|
217
206
|
{ name: "wallet", type: "address" },
|
|
218
207
|
{ name: "provider", type: "address" },
|
|
@@ -225,7 +214,7 @@ var init_constants = __esm({
|
|
|
225
214
|
}
|
|
226
215
|
});
|
|
227
216
|
|
|
228
|
-
// src/utils.ts
|
|
217
|
+
// src/core/utils.ts
|
|
229
218
|
function parseMoney(amount, decimals) {
|
|
230
219
|
if (typeof amount === "bigint") {
|
|
231
220
|
return amount;
|
|
@@ -249,7 +238,7 @@ function formatMoney(amount, decimals) {
|
|
|
249
238
|
return `${whole}.${fraction}`;
|
|
250
239
|
}
|
|
251
240
|
function getUsdcAddress(network) {
|
|
252
|
-
const address =
|
|
241
|
+
const address = TOKEN_ADDRESSES[network];
|
|
253
242
|
if (!address) {
|
|
254
243
|
throw new exports.UnsupportedNetworkError(network);
|
|
255
244
|
}
|
|
@@ -313,13 +302,13 @@ function decodePaymentResponse(header) {
|
|
|
313
302
|
}
|
|
314
303
|
}
|
|
315
304
|
var init_utils = __esm({
|
|
316
|
-
"src/utils.ts"() {
|
|
305
|
+
"src/core/utils.ts"() {
|
|
317
306
|
init_constants();
|
|
318
307
|
init_errors();
|
|
319
308
|
}
|
|
320
309
|
});
|
|
321
310
|
|
|
322
|
-
// src/signer.ts
|
|
311
|
+
// src/payment/signer.ts
|
|
323
312
|
var signer_exports = {};
|
|
324
313
|
__export(signer_exports, {
|
|
325
314
|
signD402Payment: () => signD402Payment
|
|
@@ -365,7 +354,7 @@ async function signD402Payment(params) {
|
|
|
365
354
|
const signature = await operatorAccount.signTypedData({
|
|
366
355
|
domain,
|
|
367
356
|
types: {
|
|
368
|
-
PullFundsForSettlement:
|
|
357
|
+
PullFundsForSettlement: EIP712_TYPES.PullFundsForSettlement
|
|
369
358
|
},
|
|
370
359
|
primaryType: "PullFundsForSettlement",
|
|
371
360
|
message
|
|
@@ -390,14 +379,13 @@ async function signD402Payment(params) {
|
|
|
390
379
|
return signedPayment;
|
|
391
380
|
}
|
|
392
381
|
var init_signer = __esm({
|
|
393
|
-
"src/signer.ts"() {
|
|
394
|
-
init_utils();
|
|
382
|
+
"src/payment/signer.ts"() {
|
|
395
383
|
init_utils();
|
|
396
384
|
init_constants();
|
|
397
385
|
}
|
|
398
386
|
});
|
|
399
387
|
|
|
400
|
-
// src/encoder.ts
|
|
388
|
+
// src/payment/encoder.ts
|
|
401
389
|
var encoder_exports = {};
|
|
402
390
|
__export(encoder_exports, {
|
|
403
391
|
decodePayment: () => decodePayment,
|
|
@@ -424,11 +412,11 @@ function decodePayment(encodedPayment) {
|
|
|
424
412
|
return JSON.parse(jsonString);
|
|
425
413
|
}
|
|
426
414
|
var init_encoder = __esm({
|
|
427
|
-
"src/encoder.ts"() {
|
|
415
|
+
"src/payment/encoder.ts"() {
|
|
428
416
|
}
|
|
429
417
|
});
|
|
430
418
|
|
|
431
|
-
// src/selector.ts
|
|
419
|
+
// src/payment/selector.ts
|
|
432
420
|
init_errors();
|
|
433
421
|
function selectPaymentRequirement(requirements, options = {}) {
|
|
434
422
|
const {
|
|
@@ -726,6 +714,25 @@ var sepolia_default = {
|
|
|
726
714
|
name: "ClientInitialized",
|
|
727
715
|
type: "event"
|
|
728
716
|
},
|
|
717
|
+
{
|
|
718
|
+
anonymous: false,
|
|
719
|
+
inputs: [
|
|
720
|
+
{
|
|
721
|
+
indexed: false,
|
|
722
|
+
internalType: "string",
|
|
723
|
+
name: "oldDescription",
|
|
724
|
+
type: "string"
|
|
725
|
+
},
|
|
726
|
+
{
|
|
727
|
+
indexed: false,
|
|
728
|
+
internalType: "string",
|
|
729
|
+
name: "newDescription",
|
|
730
|
+
type: "string"
|
|
731
|
+
}
|
|
732
|
+
],
|
|
733
|
+
name: "DescriptionUpdated",
|
|
734
|
+
type: "event"
|
|
735
|
+
},
|
|
729
736
|
{
|
|
730
737
|
anonymous: false,
|
|
731
738
|
inputs: [],
|
|
@@ -795,6 +802,25 @@ var sepolia_default = {
|
|
|
795
802
|
name: "Initialized",
|
|
796
803
|
type: "event"
|
|
797
804
|
},
|
|
805
|
+
{
|
|
806
|
+
anonymous: false,
|
|
807
|
+
inputs: [
|
|
808
|
+
{
|
|
809
|
+
indexed: false,
|
|
810
|
+
internalType: "string",
|
|
811
|
+
name: "oldName",
|
|
812
|
+
type: "string"
|
|
813
|
+
},
|
|
814
|
+
{
|
|
815
|
+
indexed: false,
|
|
816
|
+
internalType: "string",
|
|
817
|
+
name: "newName",
|
|
818
|
+
type: "string"
|
|
819
|
+
}
|
|
820
|
+
],
|
|
821
|
+
name: "NameUpdated",
|
|
822
|
+
type: "event"
|
|
823
|
+
},
|
|
798
824
|
{
|
|
799
825
|
anonymous: false,
|
|
800
826
|
inputs: [
|
|
@@ -840,6 +866,25 @@ var sepolia_default = {
|
|
|
840
866
|
name: "Upgraded",
|
|
841
867
|
type: "event"
|
|
842
868
|
},
|
|
869
|
+
{
|
|
870
|
+
anonymous: false,
|
|
871
|
+
inputs: [
|
|
872
|
+
{
|
|
873
|
+
indexed: true,
|
|
874
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
875
|
+
name: "oldWalletType",
|
|
876
|
+
type: "uint8"
|
|
877
|
+
},
|
|
878
|
+
{
|
|
879
|
+
indexed: true,
|
|
880
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
881
|
+
name: "newWalletType",
|
|
882
|
+
type: "uint8"
|
|
883
|
+
}
|
|
884
|
+
],
|
|
885
|
+
name: "WalletTypeUpdated",
|
|
886
|
+
type: "event"
|
|
887
|
+
},
|
|
843
888
|
{
|
|
844
889
|
anonymous: false,
|
|
845
890
|
inputs: [
|
|
@@ -1024,6 +1069,19 @@ var sepolia_default = {
|
|
|
1024
1069
|
stateMutability: "nonpayable",
|
|
1025
1070
|
type: "function"
|
|
1026
1071
|
},
|
|
1072
|
+
{
|
|
1073
|
+
inputs: [],
|
|
1074
|
+
name: "description",
|
|
1075
|
+
outputs: [
|
|
1076
|
+
{
|
|
1077
|
+
internalType: "string",
|
|
1078
|
+
name: "",
|
|
1079
|
+
type: "string"
|
|
1080
|
+
}
|
|
1081
|
+
],
|
|
1082
|
+
stateMutability: "view",
|
|
1083
|
+
type: "function"
|
|
1084
|
+
},
|
|
1027
1085
|
{
|
|
1028
1086
|
inputs: [],
|
|
1029
1087
|
name: "eip712Domain",
|
|
@@ -1185,6 +1243,21 @@ var sepolia_default = {
|
|
|
1185
1243
|
internalType: "address",
|
|
1186
1244
|
name: "_settlementLayer",
|
|
1187
1245
|
type: "address"
|
|
1246
|
+
},
|
|
1247
|
+
{
|
|
1248
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1249
|
+
name: "_walletType",
|
|
1250
|
+
type: "uint8"
|
|
1251
|
+
},
|
|
1252
|
+
{
|
|
1253
|
+
internalType: "string",
|
|
1254
|
+
name: "_name",
|
|
1255
|
+
type: "string"
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
internalType: "string",
|
|
1259
|
+
name: "_description",
|
|
1260
|
+
type: "string"
|
|
1188
1261
|
}
|
|
1189
1262
|
],
|
|
1190
1263
|
name: "initialize",
|
|
@@ -1255,6 +1328,19 @@ var sepolia_default = {
|
|
|
1255
1328
|
stateMutability: "view",
|
|
1256
1329
|
type: "function"
|
|
1257
1330
|
},
|
|
1331
|
+
{
|
|
1332
|
+
inputs: [],
|
|
1333
|
+
name: "name",
|
|
1334
|
+
outputs: [
|
|
1335
|
+
{
|
|
1336
|
+
internalType: "string",
|
|
1337
|
+
name: "",
|
|
1338
|
+
type: "string"
|
|
1339
|
+
}
|
|
1340
|
+
],
|
|
1341
|
+
stateMutability: "view",
|
|
1342
|
+
type: "function"
|
|
1343
|
+
},
|
|
1258
1344
|
{
|
|
1259
1345
|
inputs: [],
|
|
1260
1346
|
name: "operatorAddress",
|
|
@@ -1376,6 +1462,29 @@ var sepolia_default = {
|
|
|
1376
1462
|
stateMutability: "view",
|
|
1377
1463
|
type: "function"
|
|
1378
1464
|
},
|
|
1465
|
+
{
|
|
1466
|
+
inputs: [
|
|
1467
|
+
{
|
|
1468
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1469
|
+
name: "_newWalletType",
|
|
1470
|
+
type: "uint8"
|
|
1471
|
+
},
|
|
1472
|
+
{
|
|
1473
|
+
internalType: "string",
|
|
1474
|
+
name: "_newName",
|
|
1475
|
+
type: "string"
|
|
1476
|
+
},
|
|
1477
|
+
{
|
|
1478
|
+
internalType: "string",
|
|
1479
|
+
name: "_newDescription",
|
|
1480
|
+
type: "string"
|
|
1481
|
+
}
|
|
1482
|
+
],
|
|
1483
|
+
name: "updateMetadata",
|
|
1484
|
+
outputs: [],
|
|
1485
|
+
stateMutability: "nonpayable",
|
|
1486
|
+
type: "function"
|
|
1487
|
+
},
|
|
1379
1488
|
{
|
|
1380
1489
|
inputs: [
|
|
1381
1490
|
{
|
|
@@ -1489,6 +1598,19 @@ var sepolia_default = {
|
|
|
1489
1598
|
stateMutability: "view",
|
|
1490
1599
|
type: "function"
|
|
1491
1600
|
},
|
|
1601
|
+
{
|
|
1602
|
+
inputs: [],
|
|
1603
|
+
name: "walletType",
|
|
1604
|
+
outputs: [
|
|
1605
|
+
{
|
|
1606
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1607
|
+
name: "",
|
|
1608
|
+
type: "uint8"
|
|
1609
|
+
}
|
|
1610
|
+
],
|
|
1611
|
+
stateMutability: "view",
|
|
1612
|
+
type: "function"
|
|
1613
|
+
},
|
|
1492
1614
|
{
|
|
1493
1615
|
inputs: [
|
|
1494
1616
|
{
|
|
@@ -4343,6 +4465,64 @@ var sepolia_default = {
|
|
|
4343
4465
|
type: "address"
|
|
4344
4466
|
}
|
|
4345
4467
|
],
|
|
4468
|
+
name: "createClientWallet",
|
|
4469
|
+
outputs: [
|
|
4470
|
+
{
|
|
4471
|
+
internalType: "address",
|
|
4472
|
+
name: "wallet",
|
|
4473
|
+
type: "address"
|
|
4474
|
+
}
|
|
4475
|
+
],
|
|
4476
|
+
stateMutability: "nonpayable",
|
|
4477
|
+
type: "function"
|
|
4478
|
+
},
|
|
4479
|
+
{
|
|
4480
|
+
inputs: [
|
|
4481
|
+
{
|
|
4482
|
+
internalType: "address",
|
|
4483
|
+
name: "_owner",
|
|
4484
|
+
type: "address"
|
|
4485
|
+
},
|
|
4486
|
+
{
|
|
4487
|
+
internalType: "address",
|
|
4488
|
+
name: "_operatorAddress",
|
|
4489
|
+
type: "address"
|
|
4490
|
+
}
|
|
4491
|
+
],
|
|
4492
|
+
name: "createClientWalletFor",
|
|
4493
|
+
outputs: [
|
|
4494
|
+
{
|
|
4495
|
+
internalType: "address",
|
|
4496
|
+
name: "wallet",
|
|
4497
|
+
type: "address"
|
|
4498
|
+
}
|
|
4499
|
+
],
|
|
4500
|
+
stateMutability: "nonpayable",
|
|
4501
|
+
type: "function"
|
|
4502
|
+
},
|
|
4503
|
+
{
|
|
4504
|
+
inputs: [
|
|
4505
|
+
{
|
|
4506
|
+
internalType: "address",
|
|
4507
|
+
name: "_operatorAddress",
|
|
4508
|
+
type: "address"
|
|
4509
|
+
},
|
|
4510
|
+
{
|
|
4511
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
4512
|
+
name: "_walletType",
|
|
4513
|
+
type: "uint8"
|
|
4514
|
+
},
|
|
4515
|
+
{
|
|
4516
|
+
internalType: "string",
|
|
4517
|
+
name: "_name",
|
|
4518
|
+
type: "string"
|
|
4519
|
+
},
|
|
4520
|
+
{
|
|
4521
|
+
internalType: "string",
|
|
4522
|
+
name: "_description",
|
|
4523
|
+
type: "string"
|
|
4524
|
+
}
|
|
4525
|
+
],
|
|
4346
4526
|
name: "createWallet",
|
|
4347
4527
|
outputs: [
|
|
4348
4528
|
{
|
|
@@ -4365,6 +4545,21 @@ var sepolia_default = {
|
|
|
4365
4545
|
internalType: "address",
|
|
4366
4546
|
name: "_operatorAddress",
|
|
4367
4547
|
type: "address"
|
|
4548
|
+
},
|
|
4549
|
+
{
|
|
4550
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
4551
|
+
name: "_walletType",
|
|
4552
|
+
type: "uint8"
|
|
4553
|
+
},
|
|
4554
|
+
{
|
|
4555
|
+
internalType: "string",
|
|
4556
|
+
name: "_name",
|
|
4557
|
+
type: "string"
|
|
4558
|
+
},
|
|
4559
|
+
{
|
|
4560
|
+
internalType: "string",
|
|
4561
|
+
name: "_description",
|
|
4562
|
+
type: "string"
|
|
4368
4563
|
}
|
|
4369
4564
|
],
|
|
4370
4565
|
name: "createWalletFor",
|
|
@@ -4801,14 +4996,21 @@ var implementations_default = {
|
|
|
4801
4996
|
sepolia: {
|
|
4802
4997
|
Congress: "0x94Fc9eddBd1779542b78eb92F0569762603876e2",
|
|
4803
4998
|
TraiaCongressMembersRegistry: "0x3B685403b195f16D103b42FCf56F848A278d6049",
|
|
4804
|
-
IATPWalletImplementation: "
|
|
4999
|
+
IATPWalletImplementation: "0x4f9f0E1cD21f7122417A2A13b03c1BE84b7CB37E",
|
|
4805
5000
|
RoleManagerImplementation: "0x585AD85FCFBec3B1503E50b46407bF65d4006560",
|
|
4806
5001
|
IATPSettlementLayerImplementation: "0x0fDd39d323EE3538c800d4A13730eecE3F0bA975",
|
|
4807
|
-
IATPWalletFactoryImplementation: "
|
|
5002
|
+
IATPWalletFactoryImplementation: "0x4AC08c53C7ce1244a458D49A4101C3DC664e2D37"
|
|
4808
5003
|
}
|
|
4809
5004
|
};
|
|
4810
5005
|
|
|
4811
|
-
// src/contracts.ts
|
|
5006
|
+
// src/contracts/index.ts
|
|
5007
|
+
var ContractName = /* @__PURE__ */ ((ContractName2) => {
|
|
5008
|
+
ContractName2["IATP_WALLET"] = "IATPWallet";
|
|
5009
|
+
ContractName2["IATP_WALLET_FACTORY"] = "IATPWalletFactory";
|
|
5010
|
+
ContractName2["IATP_SETTLEMENT_LAYER"] = "IATPSettlementLayer";
|
|
5011
|
+
ContractName2["ROLE_MANAGER"] = "RoleManager";
|
|
5012
|
+
return ContractName2;
|
|
5013
|
+
})(ContractName || {});
|
|
4812
5014
|
var ABIS = {
|
|
4813
5015
|
sepolia: sepolia_default.sepolia || {}
|
|
4814
5016
|
};
|
|
@@ -4838,7 +5040,7 @@ function getContractConfig(contractName, network = "sepolia") {
|
|
|
4838
5040
|
return { address, abi };
|
|
4839
5041
|
}
|
|
4840
5042
|
|
|
4841
|
-
// src/wallet.ts
|
|
5043
|
+
// src/wallet/creation.ts
|
|
4842
5044
|
async function createIATPWallet(params) {
|
|
4843
5045
|
const { ownerAccount, network = "sepolia", rpcUrl } = params;
|
|
4844
5046
|
const factoryConfig = getContractConfig("IATPWalletFactory" /* IATP_WALLET_FACTORY */, network);
|
|
@@ -4866,7 +5068,7 @@ async function createIATPWallet(params) {
|
|
|
4866
5068
|
address: factoryConfig.address,
|
|
4867
5069
|
abi: factoryConfig.abi,
|
|
4868
5070
|
functionName: "createWallet",
|
|
4869
|
-
args: [operatorAddress]
|
|
5071
|
+
args: [operatorAddress, 0, "", ""]
|
|
4870
5072
|
});
|
|
4871
5073
|
const hash = await walletClient.writeContract(request);
|
|
4872
5074
|
const receipt = await publicClient.waitForTransactionReceipt({
|
|
@@ -4926,6 +5128,8 @@ async function getWalletsByOwner(params) {
|
|
|
4926
5128
|
});
|
|
4927
5129
|
return wallets;
|
|
4928
5130
|
}
|
|
5131
|
+
|
|
5132
|
+
// src/wallet/queries.ts
|
|
4929
5133
|
async function getAvailableBalance(params) {
|
|
4930
5134
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
4931
5135
|
const walletConfig = getContractConfig("IATPWallet" /* IATP_WALLET */, network);
|
|
@@ -4940,6 +5144,8 @@ async function getAvailableBalance(params) {
|
|
|
4940
5144
|
});
|
|
4941
5145
|
return balance;
|
|
4942
5146
|
}
|
|
5147
|
+
|
|
5148
|
+
// src/wallet/withdrawals.ts
|
|
4943
5149
|
async function getWithdrawalRequest(params) {
|
|
4944
5150
|
const { publicClient, walletAddress, tokenAddress, network = "sepolia" } = params;
|
|
4945
5151
|
const walletConfig = getContractConfig("IATPWallet" /* IATP_WALLET */, network);
|
|
@@ -4963,26 +5169,27 @@ async function requestWithdrawal(params) {
|
|
|
4963
5169
|
if (!walletConfig) {
|
|
4964
5170
|
throw new Error(`IATPWallet contract not found for network: ${network}`);
|
|
4965
5171
|
}
|
|
4966
|
-
|
|
5172
|
+
await publicClient.simulateContract({
|
|
5173
|
+
account,
|
|
5174
|
+
address: walletAddress,
|
|
4967
5175
|
abi: walletConfig.abi,
|
|
4968
5176
|
functionName: "requestWithdrawal",
|
|
4969
5177
|
args: [tokenAddress, amount]
|
|
4970
5178
|
});
|
|
4971
|
-
const estimatedGas = await publicClient.
|
|
4972
|
-
account: account.address,
|
|
4973
|
-
to: walletAddress,
|
|
4974
|
-
data
|
|
4975
|
-
});
|
|
4976
|
-
const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
|
|
4977
|
-
const { request } = await publicClient.simulateContract({
|
|
4978
|
-
account,
|
|
5179
|
+
const estimatedGas = await publicClient.estimateContractGas({
|
|
4979
5180
|
address: walletAddress,
|
|
4980
5181
|
abi: walletConfig.abi,
|
|
4981
5182
|
functionName: "requestWithdrawal",
|
|
4982
|
-
args: [tokenAddress, amount]
|
|
5183
|
+
args: [tokenAddress, amount],
|
|
5184
|
+
account
|
|
4983
5185
|
});
|
|
5186
|
+
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
4984
5187
|
const hash = await walletClient.writeContract({
|
|
4985
|
-
|
|
5188
|
+
address: walletAddress,
|
|
5189
|
+
abi: walletConfig.abi,
|
|
5190
|
+
functionName: "requestWithdrawal",
|
|
5191
|
+
args: [tokenAddress, amount],
|
|
5192
|
+
account,
|
|
4986
5193
|
gas: gasLimit
|
|
4987
5194
|
});
|
|
4988
5195
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
@@ -4994,33 +5201,34 @@ async function executeWithdrawal(params) {
|
|
|
4994
5201
|
if (!walletConfig) {
|
|
4995
5202
|
throw new Error(`IATPWallet contract not found for network: ${network}`);
|
|
4996
5203
|
}
|
|
4997
|
-
|
|
5204
|
+
await publicClient.simulateContract({
|
|
5205
|
+
account,
|
|
5206
|
+
address: walletAddress,
|
|
4998
5207
|
abi: walletConfig.abi,
|
|
4999
5208
|
functionName: "executeWithdrawal",
|
|
5000
5209
|
args: [tokenAddress]
|
|
5001
5210
|
});
|
|
5002
|
-
const estimatedGas = await publicClient.
|
|
5003
|
-
account: account.address,
|
|
5004
|
-
to: walletAddress,
|
|
5005
|
-
data
|
|
5006
|
-
});
|
|
5007
|
-
const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
|
|
5008
|
-
const { request } = await publicClient.simulateContract({
|
|
5009
|
-
account,
|
|
5211
|
+
const estimatedGas = await publicClient.estimateContractGas({
|
|
5010
5212
|
address: walletAddress,
|
|
5011
5213
|
abi: walletConfig.abi,
|
|
5012
5214
|
functionName: "executeWithdrawal",
|
|
5013
|
-
args: [tokenAddress]
|
|
5215
|
+
args: [tokenAddress],
|
|
5216
|
+
account
|
|
5014
5217
|
});
|
|
5218
|
+
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5015
5219
|
const hash = await walletClient.writeContract({
|
|
5016
|
-
|
|
5220
|
+
address: walletAddress,
|
|
5221
|
+
abi: walletConfig.abi,
|
|
5222
|
+
functionName: "executeWithdrawal",
|
|
5223
|
+
args: [tokenAddress],
|
|
5224
|
+
account,
|
|
5017
5225
|
gas: gasLimit
|
|
5018
5226
|
});
|
|
5019
5227
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
5020
5228
|
return hash;
|
|
5021
5229
|
}
|
|
5022
5230
|
|
|
5023
|
-
// src/client.ts
|
|
5231
|
+
// src/client/D402Client.ts
|
|
5024
5232
|
var D402Client = class {
|
|
5025
5233
|
/**
|
|
5026
5234
|
* Create a new D402 Client.
|
|
@@ -5213,9 +5421,8 @@ var D402Client = class {
|
|
|
5213
5421
|
init_signer();
|
|
5214
5422
|
init_parser();
|
|
5215
5423
|
init_encoder();
|
|
5216
|
-
|
|
5217
|
-
|
|
5218
|
-
init_constants();
|
|
5424
|
+
|
|
5425
|
+
// src/settlement/queries.ts
|
|
5219
5426
|
async function getLockedBalanceForProvider(params) {
|
|
5220
5427
|
const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
|
|
5221
5428
|
const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
|
|
@@ -5244,6 +5451,8 @@ async function getUnlockedBalanceForProvider(params) {
|
|
|
5244
5451
|
});
|
|
5245
5452
|
return balance;
|
|
5246
5453
|
}
|
|
5454
|
+
|
|
5455
|
+
// src/settlement/operations.ts
|
|
5247
5456
|
async function withdrawAllAvailableEpochs(params) {
|
|
5248
5457
|
const { walletClient, publicClient, tokenAddress, network = "sepolia" } = params;
|
|
5249
5458
|
if (!walletClient?.account) {
|
|
@@ -5254,52 +5463,65 @@ async function withdrawAllAvailableEpochs(params) {
|
|
|
5254
5463
|
if (!settlementConfig) {
|
|
5255
5464
|
throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
|
|
5256
5465
|
}
|
|
5257
|
-
|
|
5466
|
+
await publicClient.simulateContract({
|
|
5467
|
+
account,
|
|
5468
|
+
address: settlementConfig.address,
|
|
5258
5469
|
abi: settlementConfig.abi,
|
|
5259
5470
|
functionName: "withdrawAllAvailableEpochs",
|
|
5260
5471
|
args: [tokenAddress]
|
|
5261
5472
|
});
|
|
5262
|
-
const estimatedGas = await publicClient.
|
|
5263
|
-
account: account.address,
|
|
5264
|
-
to: settlementConfig.address,
|
|
5265
|
-
data
|
|
5266
|
-
});
|
|
5267
|
-
const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
|
|
5268
|
-
const { request } = await publicClient.simulateContract({
|
|
5269
|
-
account,
|
|
5473
|
+
const estimatedGas = await publicClient.estimateContractGas({
|
|
5270
5474
|
address: settlementConfig.address,
|
|
5271
5475
|
abi: settlementConfig.abi,
|
|
5272
5476
|
functionName: "withdrawAllAvailableEpochs",
|
|
5273
|
-
args: [tokenAddress]
|
|
5477
|
+
args: [tokenAddress],
|
|
5478
|
+
account
|
|
5274
5479
|
});
|
|
5480
|
+
const gasLimit = estimatedGas + estimatedGas / 5n;
|
|
5275
5481
|
const hash = await walletClient.writeContract({
|
|
5276
|
-
|
|
5482
|
+
address: settlementConfig.address,
|
|
5483
|
+
abi: settlementConfig.abi,
|
|
5484
|
+
functionName: "withdrawAllAvailableEpochs",
|
|
5485
|
+
args: [tokenAddress],
|
|
5486
|
+
account,
|
|
5277
5487
|
gas: gasLimit
|
|
5278
5488
|
});
|
|
5279
5489
|
await publicClient.waitForTransactionReceipt({ hash });
|
|
5280
5490
|
return hash;
|
|
5281
5491
|
}
|
|
5282
5492
|
|
|
5493
|
+
// src/index.ts
|
|
5494
|
+
init_utils();
|
|
5495
|
+
init_errors();
|
|
5496
|
+
|
|
5497
|
+
exports.ContractName = ContractName;
|
|
5283
5498
|
exports.D402Client = D402Client;
|
|
5284
5499
|
exports.createIATPWallet = createIATPWallet;
|
|
5285
5500
|
exports.createPaymentSelector = createPaymentSelector;
|
|
5286
5501
|
exports.decodePayment = decodePayment;
|
|
5287
5502
|
exports.decodePaymentResponse = decodePaymentResponse;
|
|
5288
5503
|
exports.encodePayment = encodePayment;
|
|
5504
|
+
exports.executeWithdrawal = executeWithdrawal;
|
|
5289
5505
|
exports.findMatchingPaymentRequirement = findMatchingPaymentRequirement;
|
|
5290
5506
|
exports.formatMoney = formatMoney;
|
|
5291
5507
|
exports.generateNonce = generateNonce;
|
|
5292
5508
|
exports.getAvailableBalance = getAvailableBalance;
|
|
5293
5509
|
exports.getChainId = getChainId;
|
|
5510
|
+
exports.getContractAbi = getContractAbi;
|
|
5511
|
+
exports.getContractAddress = getContractAddress;
|
|
5512
|
+
exports.getContractConfig = getContractConfig;
|
|
5294
5513
|
exports.getCurrentTimestamp = getCurrentTimestamp;
|
|
5295
5514
|
exports.getLockedBalanceForProvider = getLockedBalanceForProvider;
|
|
5296
5515
|
exports.getUnlockedBalanceForProvider = getUnlockedBalanceForProvider;
|
|
5297
5516
|
exports.getUsdcAddress = getUsdcAddress;
|
|
5298
5517
|
exports.getWalletsByOwner = getWalletsByOwner;
|
|
5518
|
+
exports.getWithdrawalRequest = getWithdrawalRequest;
|
|
5299
5519
|
exports.isValidAddress = isValidAddress;
|
|
5300
5520
|
exports.normalizeAddress = normalizeAddress;
|
|
5521
|
+
exports.parseAllPaymentRequirements = parseAllPaymentRequirements;
|
|
5301
5522
|
exports.parseMoney = parseMoney;
|
|
5302
5523
|
exports.parsePaymentRequirement = parsePaymentRequirement;
|
|
5524
|
+
exports.requestWithdrawal = requestWithdrawal;
|
|
5303
5525
|
exports.selectPaymentRequirement = selectPaymentRequirement;
|
|
5304
5526
|
exports.signD402Payment = signD402Payment;
|
|
5305
5527
|
exports.sortPaymentRequirements = sortPaymentRequirements;
|