@dcentralab/d402-client 0.2.5 → 0.2.7
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 +35 -98
- package/dist/index.d.ts +35 -98
- package/dist/index.js +246 -26
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +247 -22
- 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;
|
|
@@ -724,6 +724,25 @@ var sepolia_default = {
|
|
|
724
724
|
name: "ClientInitialized",
|
|
725
725
|
type: "event"
|
|
726
726
|
},
|
|
727
|
+
{
|
|
728
|
+
anonymous: false,
|
|
729
|
+
inputs: [
|
|
730
|
+
{
|
|
731
|
+
indexed: false,
|
|
732
|
+
internalType: "string",
|
|
733
|
+
name: "oldDescription",
|
|
734
|
+
type: "string"
|
|
735
|
+
},
|
|
736
|
+
{
|
|
737
|
+
indexed: false,
|
|
738
|
+
internalType: "string",
|
|
739
|
+
name: "newDescription",
|
|
740
|
+
type: "string"
|
|
741
|
+
}
|
|
742
|
+
],
|
|
743
|
+
name: "DescriptionUpdated",
|
|
744
|
+
type: "event"
|
|
745
|
+
},
|
|
727
746
|
{
|
|
728
747
|
anonymous: false,
|
|
729
748
|
inputs: [],
|
|
@@ -793,6 +812,25 @@ var sepolia_default = {
|
|
|
793
812
|
name: "Initialized",
|
|
794
813
|
type: "event"
|
|
795
814
|
},
|
|
815
|
+
{
|
|
816
|
+
anonymous: false,
|
|
817
|
+
inputs: [
|
|
818
|
+
{
|
|
819
|
+
indexed: false,
|
|
820
|
+
internalType: "string",
|
|
821
|
+
name: "oldName",
|
|
822
|
+
type: "string"
|
|
823
|
+
},
|
|
824
|
+
{
|
|
825
|
+
indexed: false,
|
|
826
|
+
internalType: "string",
|
|
827
|
+
name: "newName",
|
|
828
|
+
type: "string"
|
|
829
|
+
}
|
|
830
|
+
],
|
|
831
|
+
name: "NameUpdated",
|
|
832
|
+
type: "event"
|
|
833
|
+
},
|
|
796
834
|
{
|
|
797
835
|
anonymous: false,
|
|
798
836
|
inputs: [
|
|
@@ -838,6 +876,25 @@ var sepolia_default = {
|
|
|
838
876
|
name: "Upgraded",
|
|
839
877
|
type: "event"
|
|
840
878
|
},
|
|
879
|
+
{
|
|
880
|
+
anonymous: false,
|
|
881
|
+
inputs: [
|
|
882
|
+
{
|
|
883
|
+
indexed: true,
|
|
884
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
885
|
+
name: "oldWalletType",
|
|
886
|
+
type: "uint8"
|
|
887
|
+
},
|
|
888
|
+
{
|
|
889
|
+
indexed: true,
|
|
890
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
891
|
+
name: "newWalletType",
|
|
892
|
+
type: "uint8"
|
|
893
|
+
}
|
|
894
|
+
],
|
|
895
|
+
name: "WalletTypeUpdated",
|
|
896
|
+
type: "event"
|
|
897
|
+
},
|
|
841
898
|
{
|
|
842
899
|
anonymous: false,
|
|
843
900
|
inputs: [
|
|
@@ -1022,6 +1079,19 @@ var sepolia_default = {
|
|
|
1022
1079
|
stateMutability: "nonpayable",
|
|
1023
1080
|
type: "function"
|
|
1024
1081
|
},
|
|
1082
|
+
{
|
|
1083
|
+
inputs: [],
|
|
1084
|
+
name: "description",
|
|
1085
|
+
outputs: [
|
|
1086
|
+
{
|
|
1087
|
+
internalType: "string",
|
|
1088
|
+
name: "",
|
|
1089
|
+
type: "string"
|
|
1090
|
+
}
|
|
1091
|
+
],
|
|
1092
|
+
stateMutability: "view",
|
|
1093
|
+
type: "function"
|
|
1094
|
+
},
|
|
1025
1095
|
{
|
|
1026
1096
|
inputs: [],
|
|
1027
1097
|
name: "eip712Domain",
|
|
@@ -1183,6 +1253,21 @@ var sepolia_default = {
|
|
|
1183
1253
|
internalType: "address",
|
|
1184
1254
|
name: "_settlementLayer",
|
|
1185
1255
|
type: "address"
|
|
1256
|
+
},
|
|
1257
|
+
{
|
|
1258
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1259
|
+
name: "_walletType",
|
|
1260
|
+
type: "uint8"
|
|
1261
|
+
},
|
|
1262
|
+
{
|
|
1263
|
+
internalType: "string",
|
|
1264
|
+
name: "_name",
|
|
1265
|
+
type: "string"
|
|
1266
|
+
},
|
|
1267
|
+
{
|
|
1268
|
+
internalType: "string",
|
|
1269
|
+
name: "_description",
|
|
1270
|
+
type: "string"
|
|
1186
1271
|
}
|
|
1187
1272
|
],
|
|
1188
1273
|
name: "initialize",
|
|
@@ -1253,6 +1338,19 @@ var sepolia_default = {
|
|
|
1253
1338
|
stateMutability: "view",
|
|
1254
1339
|
type: "function"
|
|
1255
1340
|
},
|
|
1341
|
+
{
|
|
1342
|
+
inputs: [],
|
|
1343
|
+
name: "name",
|
|
1344
|
+
outputs: [
|
|
1345
|
+
{
|
|
1346
|
+
internalType: "string",
|
|
1347
|
+
name: "",
|
|
1348
|
+
type: "string"
|
|
1349
|
+
}
|
|
1350
|
+
],
|
|
1351
|
+
stateMutability: "view",
|
|
1352
|
+
type: "function"
|
|
1353
|
+
},
|
|
1256
1354
|
{
|
|
1257
1355
|
inputs: [],
|
|
1258
1356
|
name: "operatorAddress",
|
|
@@ -1374,6 +1472,29 @@ var sepolia_default = {
|
|
|
1374
1472
|
stateMutability: "view",
|
|
1375
1473
|
type: "function"
|
|
1376
1474
|
},
|
|
1475
|
+
{
|
|
1476
|
+
inputs: [
|
|
1477
|
+
{
|
|
1478
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1479
|
+
name: "_newWalletType",
|
|
1480
|
+
type: "uint8"
|
|
1481
|
+
},
|
|
1482
|
+
{
|
|
1483
|
+
internalType: "string",
|
|
1484
|
+
name: "_newName",
|
|
1485
|
+
type: "string"
|
|
1486
|
+
},
|
|
1487
|
+
{
|
|
1488
|
+
internalType: "string",
|
|
1489
|
+
name: "_newDescription",
|
|
1490
|
+
type: "string"
|
|
1491
|
+
}
|
|
1492
|
+
],
|
|
1493
|
+
name: "updateMetadata",
|
|
1494
|
+
outputs: [],
|
|
1495
|
+
stateMutability: "nonpayable",
|
|
1496
|
+
type: "function"
|
|
1497
|
+
},
|
|
1377
1498
|
{
|
|
1378
1499
|
inputs: [
|
|
1379
1500
|
{
|
|
@@ -1487,6 +1608,19 @@ var sepolia_default = {
|
|
|
1487
1608
|
stateMutability: "view",
|
|
1488
1609
|
type: "function"
|
|
1489
1610
|
},
|
|
1611
|
+
{
|
|
1612
|
+
inputs: [],
|
|
1613
|
+
name: "walletType",
|
|
1614
|
+
outputs: [
|
|
1615
|
+
{
|
|
1616
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
1617
|
+
name: "",
|
|
1618
|
+
type: "uint8"
|
|
1619
|
+
}
|
|
1620
|
+
],
|
|
1621
|
+
stateMutability: "view",
|
|
1622
|
+
type: "function"
|
|
1623
|
+
},
|
|
1490
1624
|
{
|
|
1491
1625
|
inputs: [
|
|
1492
1626
|
{
|
|
@@ -4341,6 +4475,64 @@ var sepolia_default = {
|
|
|
4341
4475
|
type: "address"
|
|
4342
4476
|
}
|
|
4343
4477
|
],
|
|
4478
|
+
name: "createClientWallet",
|
|
4479
|
+
outputs: [
|
|
4480
|
+
{
|
|
4481
|
+
internalType: "address",
|
|
4482
|
+
name: "wallet",
|
|
4483
|
+
type: "address"
|
|
4484
|
+
}
|
|
4485
|
+
],
|
|
4486
|
+
stateMutability: "nonpayable",
|
|
4487
|
+
type: "function"
|
|
4488
|
+
},
|
|
4489
|
+
{
|
|
4490
|
+
inputs: [
|
|
4491
|
+
{
|
|
4492
|
+
internalType: "address",
|
|
4493
|
+
name: "_owner",
|
|
4494
|
+
type: "address"
|
|
4495
|
+
},
|
|
4496
|
+
{
|
|
4497
|
+
internalType: "address",
|
|
4498
|
+
name: "_operatorAddress",
|
|
4499
|
+
type: "address"
|
|
4500
|
+
}
|
|
4501
|
+
],
|
|
4502
|
+
name: "createClientWalletFor",
|
|
4503
|
+
outputs: [
|
|
4504
|
+
{
|
|
4505
|
+
internalType: "address",
|
|
4506
|
+
name: "wallet",
|
|
4507
|
+
type: "address"
|
|
4508
|
+
}
|
|
4509
|
+
],
|
|
4510
|
+
stateMutability: "nonpayable",
|
|
4511
|
+
type: "function"
|
|
4512
|
+
},
|
|
4513
|
+
{
|
|
4514
|
+
inputs: [
|
|
4515
|
+
{
|
|
4516
|
+
internalType: "address",
|
|
4517
|
+
name: "_operatorAddress",
|
|
4518
|
+
type: "address"
|
|
4519
|
+
},
|
|
4520
|
+
{
|
|
4521
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
4522
|
+
name: "_walletType",
|
|
4523
|
+
type: "uint8"
|
|
4524
|
+
},
|
|
4525
|
+
{
|
|
4526
|
+
internalType: "string",
|
|
4527
|
+
name: "_name",
|
|
4528
|
+
type: "string"
|
|
4529
|
+
},
|
|
4530
|
+
{
|
|
4531
|
+
internalType: "string",
|
|
4532
|
+
name: "_description",
|
|
4533
|
+
type: "string"
|
|
4534
|
+
}
|
|
4535
|
+
],
|
|
4344
4536
|
name: "createWallet",
|
|
4345
4537
|
outputs: [
|
|
4346
4538
|
{
|
|
@@ -4363,6 +4555,21 @@ var sepolia_default = {
|
|
|
4363
4555
|
internalType: "address",
|
|
4364
4556
|
name: "_operatorAddress",
|
|
4365
4557
|
type: "address"
|
|
4558
|
+
},
|
|
4559
|
+
{
|
|
4560
|
+
internalType: "enum IIATPWalletFactory.WalletType",
|
|
4561
|
+
name: "_walletType",
|
|
4562
|
+
type: "uint8"
|
|
4563
|
+
},
|
|
4564
|
+
{
|
|
4565
|
+
internalType: "string",
|
|
4566
|
+
name: "_name",
|
|
4567
|
+
type: "string"
|
|
4568
|
+
},
|
|
4569
|
+
{
|
|
4570
|
+
internalType: "string",
|
|
4571
|
+
name: "_description",
|
|
4572
|
+
type: "string"
|
|
4366
4573
|
}
|
|
4367
4574
|
],
|
|
4368
4575
|
name: "createWalletFor",
|
|
@@ -4799,21 +5006,14 @@ var implementations_default = {
|
|
|
4799
5006
|
sepolia: {
|
|
4800
5007
|
Congress: "0x94Fc9eddBd1779542b78eb92F0569762603876e2",
|
|
4801
5008
|
TraiaCongressMembersRegistry: "0x3B685403b195f16D103b42FCf56F848A278d6049",
|
|
4802
|
-
IATPWalletImplementation: "
|
|
5009
|
+
IATPWalletImplementation: "0x4f9f0E1cD21f7122417A2A13b03c1BE84b7CB37E",
|
|
4803
5010
|
RoleManagerImplementation: "0x585AD85FCFBec3B1503E50b46407bF65d4006560",
|
|
4804
5011
|
IATPSettlementLayerImplementation: "0x0fDd39d323EE3538c800d4A13730eecE3F0bA975",
|
|
4805
|
-
IATPWalletFactoryImplementation: "
|
|
5012
|
+
IATPWalletFactoryImplementation: "0x4AC08c53C7ce1244a458D49A4101C3DC664e2D37"
|
|
4806
5013
|
}
|
|
4807
5014
|
};
|
|
4808
5015
|
|
|
4809
5016
|
// 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
5017
|
var ABIS = {
|
|
4818
5018
|
sepolia: sepolia_default.sepolia || {}
|
|
4819
5019
|
};
|
|
@@ -4842,14 +5042,6 @@ function getContractConfig(contractName, network = "sepolia") {
|
|
|
4842
5042
|
}
|
|
4843
5043
|
return { address, abi };
|
|
4844
5044
|
}
|
|
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
5045
|
|
|
4854
5046
|
// src/wallet.ts
|
|
4855
5047
|
async function createIATPWallet(params) {
|
|
@@ -4879,7 +5071,7 @@ async function createIATPWallet(params) {
|
|
|
4879
5071
|
address: factoryConfig.address,
|
|
4880
5072
|
abi: factoryConfig.abi,
|
|
4881
5073
|
functionName: "createWallet",
|
|
4882
|
-
args: [operatorAddress]
|
|
5074
|
+
args: [operatorAddress, 0, "", ""]
|
|
4883
5075
|
});
|
|
4884
5076
|
const hash = await walletClient.writeContract(request);
|
|
4885
5077
|
const receipt = await publicClient.waitForTransactionReceipt({
|
|
@@ -5229,8 +5421,6 @@ init_encoder();
|
|
|
5229
5421
|
init_utils();
|
|
5230
5422
|
init_errors();
|
|
5231
5423
|
init_constants();
|
|
5232
|
-
|
|
5233
|
-
// src/settlement.ts
|
|
5234
5424
|
async function getLockedBalanceForProvider(params) {
|
|
5235
5425
|
const { publicClient, providerAddress, tokenAddress, network = "sepolia" } = params;
|
|
5236
5426
|
const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
|
|
@@ -5259,7 +5449,42 @@ async function getUnlockedBalanceForProvider(params) {
|
|
|
5259
5449
|
});
|
|
5260
5450
|
return balance;
|
|
5261
5451
|
}
|
|
5452
|
+
async function withdrawAllAvailableEpochs(params) {
|
|
5453
|
+
const { walletClient, publicClient, tokenAddress, network = "sepolia" } = params;
|
|
5454
|
+
if (!walletClient?.account) {
|
|
5455
|
+
throw new Error("Wallet account not found. Please connect your wallet.");
|
|
5456
|
+
}
|
|
5457
|
+
const account = walletClient.account;
|
|
5458
|
+
const settlementConfig = getContractConfig("IATPSettlementLayer" /* IATP_SETTLEMENT_LAYER */, network);
|
|
5459
|
+
if (!settlementConfig) {
|
|
5460
|
+
throw new Error(`IATPSettlementLayer contract not found for network: ${network}`);
|
|
5461
|
+
}
|
|
5462
|
+
const data = encodeFunctionData({
|
|
5463
|
+
abi: settlementConfig.abi,
|
|
5464
|
+
functionName: "withdrawAllAvailableEpochs",
|
|
5465
|
+
args: [tokenAddress]
|
|
5466
|
+
});
|
|
5467
|
+
const estimatedGas = await publicClient.estimateGas({
|
|
5468
|
+
account: account.address,
|
|
5469
|
+
to: settlementConfig.address,
|
|
5470
|
+
data
|
|
5471
|
+
});
|
|
5472
|
+
const gasLimit = estimatedGas + estimatedGas * BigInt(20) / BigInt(100);
|
|
5473
|
+
const { request } = await publicClient.simulateContract({
|
|
5474
|
+
account,
|
|
5475
|
+
address: settlementConfig.address,
|
|
5476
|
+
abi: settlementConfig.abi,
|
|
5477
|
+
functionName: "withdrawAllAvailableEpochs",
|
|
5478
|
+
args: [tokenAddress]
|
|
5479
|
+
});
|
|
5480
|
+
const hash = await walletClient.writeContract({
|
|
5481
|
+
...request,
|
|
5482
|
+
gas: gasLimit
|
|
5483
|
+
});
|
|
5484
|
+
await publicClient.waitForTransactionReceipt({ hash });
|
|
5485
|
+
return hash;
|
|
5486
|
+
}
|
|
5262
5487
|
|
|
5263
|
-
export { CHAIN_IDS,
|
|
5488
|
+
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
5489
|
//# sourceMappingURL=index.mjs.map
|
|
5265
5490
|
//# sourceMappingURL=index.mjs.map
|