@layr-labs/ecloud-sdk 0.4.0-dev.0 → 0.4.0-dev.2

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.
Files changed (40) hide show
  1. package/VERSION +2 -0
  2. package/dist/attest.cjs +185 -0
  3. package/dist/attest.cjs.map +1 -0
  4. package/dist/attest.d.cts +28 -0
  5. package/dist/attest.d.ts +28 -0
  6. package/dist/attest.js +147 -0
  7. package/dist/attest.js.map +1 -0
  8. package/dist/billing.cjs +1380 -4
  9. package/dist/billing.cjs.map +1 -1
  10. package/dist/billing.d.cts +25 -3
  11. package/dist/billing.d.ts +25 -3
  12. package/dist/billing.js +1380 -4
  13. package/dist/billing.js.map +1 -1
  14. package/dist/browser.cjs +3 -2
  15. package/dist/browser.cjs.map +1 -1
  16. package/dist/browser.d.cts +4 -4
  17. package/dist/browser.d.ts +4 -4
  18. package/dist/browser.js +3 -2
  19. package/dist/browser.js.map +1 -1
  20. package/dist/{compute-DccJLbtV.d.cts → compute-BRDk7QM4.d.cts} +1 -1
  21. package/dist/{compute-DlilmZYC.d.ts → compute-CC55YQ_a.d.ts} +1 -1
  22. package/dist/compute.cjs +8 -3
  23. package/dist/compute.cjs.map +1 -1
  24. package/dist/compute.d.cts +2 -2
  25. package/dist/compute.d.ts +2 -2
  26. package/dist/compute.js +8 -3
  27. package/dist/compute.js.map +1 -1
  28. package/dist/{helpers-D_AbDeP4.d.ts → helpers-BcoV07Me.d.ts} +1 -1
  29. package/dist/{helpers-BNeMZYcY.d.cts → helpers-DdtPaQr9.d.cts} +1 -1
  30. package/dist/{index-DD7ZLbqD.d.cts → index-BEbhrwWl.d.cts} +1 -0
  31. package/dist/{index-DD7ZLbqD.d.ts → index-BEbhrwWl.d.ts} +1 -0
  32. package/dist/index.cjs +330 -95
  33. package/dist/index.cjs.map +1 -1
  34. package/dist/index.d.cts +7 -6
  35. package/dist/index.d.ts +7 -6
  36. package/dist/index.js +328 -95
  37. package/dist/index.js.map +1 -1
  38. package/package.json +6 -1
  39. package/tools/kms-client-linux-amd64 +0 -0
  40. package/tools/tls-keygen-linux-amd64 +0 -0
package/dist/billing.cjs CHANGED
@@ -44,6 +44,9 @@ __export(billing_exports, {
44
44
  });
45
45
  module.exports = __toCommonJS(billing_exports);
46
46
 
47
+ // src/client/modules/billing/index.ts
48
+ var import_viem5 = require("viem");
49
+
47
50
  // src/client/common/utils/billingapi.ts
48
51
  var import_axios = __toESM(require("axios"), 1);
49
52
 
@@ -473,7 +476,8 @@ var ENVIRONMENTS = {
473
476
  erc7702DelegatorAddress: CommonAddresses.ERC7702Delegator,
474
477
  kmsServerURL: "http://10.128.15.203:8080",
475
478
  userApiServerURL: "https://userapi-compute-sepolia-prod.eigencloud.xyz",
476
- defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com"
479
+ defaultRPCURL: "https://ethereum-sepolia-rpc.publicnode.com",
480
+ billingRPCURL: "https://ethereum-rpc.publicnode.com"
477
481
  },
478
482
  "mainnet-alpha": {
479
483
  name: "mainnet-alpha",
@@ -490,6 +494,28 @@ var CHAIN_ID_TO_ENVIRONMENT = {
490
494
  [SEPOLIA_CHAIN_ID.toString()]: "sepolia",
491
495
  [MAINNET_CHAIN_ID.toString()]: "mainnet-alpha"
492
496
  };
497
+ function getEnvironmentConfig(environment, chainID) {
498
+ const env = ENVIRONMENTS[environment];
499
+ if (!env) {
500
+ throw new Error(`Unknown environment: ${environment}`);
501
+ }
502
+ if (!isEnvironmentAvailable(environment)) {
503
+ throw new Error(
504
+ `Environment ${environment} is not available in this build type. Available environments: ${getAvailableEnvironments().join(", ")}`
505
+ );
506
+ }
507
+ if (chainID) {
508
+ const expectedEnv = CHAIN_ID_TO_ENVIRONMENT[chainID.toString()];
509
+ if (expectedEnv && expectedEnv !== environment) {
510
+ throw new Error(`Environment ${environment} does not match chain ID ${chainID}`);
511
+ }
512
+ }
513
+ const resolvedChainID = chainID || (environment === "sepolia" || environment === "sepolia-dev" ? SEPOLIA_CHAIN_ID : MAINNET_CHAIN_ID);
514
+ return {
515
+ ...env,
516
+ chainID: BigInt(resolvedChainID)
517
+ };
518
+ }
493
519
  function getBillingEnvironmentConfig(build) {
494
520
  const config = BILLING_ENVIRONMENTS[build];
495
521
  if (!config) {
@@ -506,6 +532,16 @@ function getBuildType() {
506
532
  }
507
533
  return "prod";
508
534
  }
535
+ function getAvailableEnvironments() {
536
+ const buildType = getBuildType();
537
+ if (buildType === "dev") {
538
+ return ["sepolia-dev"];
539
+ }
540
+ return ["sepolia", "mainnet-alpha"];
541
+ }
542
+ function isEnvironmentAvailable(environment) {
543
+ return getAvailableEnvironments().includes(environment);
544
+ }
509
545
 
510
546
  // src/client/common/utils/logger.ts
511
547
  var getLogger = (verbose) => ({
@@ -611,7 +647,7 @@ function getPostHogAPIKey() {
611
647
  if (process.env.ECLOUD_POSTHOG_KEY) {
612
648
  return process.env.ECLOUD_POSTHOG_KEY;
613
649
  }
614
- return typeof POSTHOG_API_KEY_BUILD_TIME !== "undefined" ? POSTHOG_API_KEY_BUILD_TIME : void 0;
650
+ return true ? "phc_BiKfywNft5iBI8N7MxmuVCkb4GGZj4mDFXYPmOPUAI8" : void 0;
615
651
  }
616
652
  function getPostHogEndpoint() {
617
653
  return process.env.ECLOUD_POSTHOG_ENDPOINT || "https://us.i.posthog.com";
@@ -732,9 +768,1271 @@ async function withSDKTelemetry(options, action) {
732
768
  }
733
769
  }
734
770
 
771
+ // src/client/common/contract/eip7702.ts
772
+ var import_viem4 = require("viem");
773
+
774
+ // src/client/common/types/index.ts
775
+ var noopLogger = {
776
+ debug: () => {
777
+ },
778
+ info: () => {
779
+ },
780
+ warn: () => {
781
+ },
782
+ error: () => {
783
+ }
784
+ };
785
+
786
+ // src/client/common/abis/ERC7702Delegator.json
787
+ var ERC7702Delegator_default = [
788
+ {
789
+ type: "constructor",
790
+ inputs: [
791
+ {
792
+ name: "_delegationManager",
793
+ type: "address",
794
+ internalType: "contractIDelegationManager"
795
+ },
796
+ {
797
+ name: "_entryPoint",
798
+ type: "address",
799
+ internalType: "contractIEntryPoint"
800
+ }
801
+ ],
802
+ stateMutability: "nonpayable"
803
+ },
804
+ {
805
+ type: "receive",
806
+ stateMutability: "payable"
807
+ },
808
+ {
809
+ type: "function",
810
+ name: "DOMAIN_VERSION",
811
+ inputs: [],
812
+ outputs: [
813
+ {
814
+ name: "",
815
+ type: "string",
816
+ internalType: "string"
817
+ }
818
+ ],
819
+ stateMutability: "view"
820
+ },
821
+ {
822
+ type: "function",
823
+ name: "NAME",
824
+ inputs: [],
825
+ outputs: [
826
+ {
827
+ name: "",
828
+ type: "string",
829
+ internalType: "string"
830
+ }
831
+ ],
832
+ stateMutability: "view"
833
+ },
834
+ {
835
+ type: "function",
836
+ name: "PACKED_USER_OP_TYPEHASH",
837
+ inputs: [],
838
+ outputs: [
839
+ {
840
+ name: "",
841
+ type: "bytes32",
842
+ internalType: "bytes32"
843
+ }
844
+ ],
845
+ stateMutability: "view"
846
+ },
847
+ {
848
+ type: "function",
849
+ name: "VERSION",
850
+ inputs: [],
851
+ outputs: [
852
+ {
853
+ name: "",
854
+ type: "string",
855
+ internalType: "string"
856
+ }
857
+ ],
858
+ stateMutability: "view"
859
+ },
860
+ {
861
+ type: "function",
862
+ name: "addDeposit",
863
+ inputs: [],
864
+ outputs: [],
865
+ stateMutability: "payable"
866
+ },
867
+ {
868
+ type: "function",
869
+ name: "delegationManager",
870
+ inputs: [],
871
+ outputs: [
872
+ {
873
+ name: "",
874
+ type: "address",
875
+ internalType: "contractIDelegationManager"
876
+ }
877
+ ],
878
+ stateMutability: "view"
879
+ },
880
+ {
881
+ type: "function",
882
+ name: "disableDelegation",
883
+ inputs: [
884
+ {
885
+ name: "_delegation",
886
+ type: "tuple",
887
+ internalType: "structDelegation",
888
+ components: [
889
+ {
890
+ name: "delegate",
891
+ type: "address",
892
+ internalType: "address"
893
+ },
894
+ {
895
+ name: "delegator",
896
+ type: "address",
897
+ internalType: "address"
898
+ },
899
+ {
900
+ name: "authority",
901
+ type: "bytes32",
902
+ internalType: "bytes32"
903
+ },
904
+ {
905
+ name: "caveats",
906
+ type: "tuple[]",
907
+ internalType: "structCaveat[]",
908
+ components: [
909
+ {
910
+ name: "enforcer",
911
+ type: "address",
912
+ internalType: "address"
913
+ },
914
+ {
915
+ name: "terms",
916
+ type: "bytes",
917
+ internalType: "bytes"
918
+ },
919
+ {
920
+ name: "args",
921
+ type: "bytes",
922
+ internalType: "bytes"
923
+ }
924
+ ]
925
+ },
926
+ {
927
+ name: "salt",
928
+ type: "uint256",
929
+ internalType: "uint256"
930
+ },
931
+ {
932
+ name: "signature",
933
+ type: "bytes",
934
+ internalType: "bytes"
935
+ }
936
+ ]
937
+ }
938
+ ],
939
+ outputs: [],
940
+ stateMutability: "nonpayable"
941
+ },
942
+ {
943
+ type: "function",
944
+ name: "eip712Domain",
945
+ inputs: [],
946
+ outputs: [
947
+ {
948
+ name: "fields",
949
+ type: "bytes1",
950
+ internalType: "bytes1"
951
+ },
952
+ {
953
+ name: "name",
954
+ type: "string",
955
+ internalType: "string"
956
+ },
957
+ {
958
+ name: "version",
959
+ type: "string",
960
+ internalType: "string"
961
+ },
962
+ {
963
+ name: "chainId",
964
+ type: "uint256",
965
+ internalType: "uint256"
966
+ },
967
+ {
968
+ name: "verifyingContract",
969
+ type: "address",
970
+ internalType: "address"
971
+ },
972
+ {
973
+ name: "salt",
974
+ type: "bytes32",
975
+ internalType: "bytes32"
976
+ },
977
+ {
978
+ name: "extensions",
979
+ type: "uint256[]",
980
+ internalType: "uint256[]"
981
+ }
982
+ ],
983
+ stateMutability: "view"
984
+ },
985
+ {
986
+ type: "function",
987
+ name: "enableDelegation",
988
+ inputs: [
989
+ {
990
+ name: "_delegation",
991
+ type: "tuple",
992
+ internalType: "structDelegation",
993
+ components: [
994
+ {
995
+ name: "delegate",
996
+ type: "address",
997
+ internalType: "address"
998
+ },
999
+ {
1000
+ name: "delegator",
1001
+ type: "address",
1002
+ internalType: "address"
1003
+ },
1004
+ {
1005
+ name: "authority",
1006
+ type: "bytes32",
1007
+ internalType: "bytes32"
1008
+ },
1009
+ {
1010
+ name: "caveats",
1011
+ type: "tuple[]",
1012
+ internalType: "structCaveat[]",
1013
+ components: [
1014
+ {
1015
+ name: "enforcer",
1016
+ type: "address",
1017
+ internalType: "address"
1018
+ },
1019
+ {
1020
+ name: "terms",
1021
+ type: "bytes",
1022
+ internalType: "bytes"
1023
+ },
1024
+ {
1025
+ name: "args",
1026
+ type: "bytes",
1027
+ internalType: "bytes"
1028
+ }
1029
+ ]
1030
+ },
1031
+ {
1032
+ name: "salt",
1033
+ type: "uint256",
1034
+ internalType: "uint256"
1035
+ },
1036
+ {
1037
+ name: "signature",
1038
+ type: "bytes",
1039
+ internalType: "bytes"
1040
+ }
1041
+ ]
1042
+ }
1043
+ ],
1044
+ outputs: [],
1045
+ stateMutability: "nonpayable"
1046
+ },
1047
+ {
1048
+ type: "function",
1049
+ name: "entryPoint",
1050
+ inputs: [],
1051
+ outputs: [
1052
+ {
1053
+ name: "",
1054
+ type: "address",
1055
+ internalType: "contractIEntryPoint"
1056
+ }
1057
+ ],
1058
+ stateMutability: "view"
1059
+ },
1060
+ {
1061
+ type: "function",
1062
+ name: "execute",
1063
+ inputs: [
1064
+ {
1065
+ name: "_execution",
1066
+ type: "tuple",
1067
+ internalType: "structExecution",
1068
+ components: [
1069
+ {
1070
+ name: "target",
1071
+ type: "address",
1072
+ internalType: "address"
1073
+ },
1074
+ {
1075
+ name: "value",
1076
+ type: "uint256",
1077
+ internalType: "uint256"
1078
+ },
1079
+ {
1080
+ name: "callData",
1081
+ type: "bytes",
1082
+ internalType: "bytes"
1083
+ }
1084
+ ]
1085
+ }
1086
+ ],
1087
+ outputs: [],
1088
+ stateMutability: "payable"
1089
+ },
1090
+ {
1091
+ type: "function",
1092
+ name: "execute",
1093
+ inputs: [
1094
+ {
1095
+ name: "_mode",
1096
+ type: "bytes32",
1097
+ internalType: "ModeCode"
1098
+ },
1099
+ {
1100
+ name: "_executionCalldata",
1101
+ type: "bytes",
1102
+ internalType: "bytes"
1103
+ }
1104
+ ],
1105
+ outputs: [],
1106
+ stateMutability: "payable"
1107
+ },
1108
+ {
1109
+ type: "function",
1110
+ name: "executeFromExecutor",
1111
+ inputs: [
1112
+ {
1113
+ name: "_mode",
1114
+ type: "bytes32",
1115
+ internalType: "ModeCode"
1116
+ },
1117
+ {
1118
+ name: "_executionCalldata",
1119
+ type: "bytes",
1120
+ internalType: "bytes"
1121
+ }
1122
+ ],
1123
+ outputs: [
1124
+ {
1125
+ name: "returnData_",
1126
+ type: "bytes[]",
1127
+ internalType: "bytes[]"
1128
+ }
1129
+ ],
1130
+ stateMutability: "payable"
1131
+ },
1132
+ {
1133
+ type: "function",
1134
+ name: "getDeposit",
1135
+ inputs: [],
1136
+ outputs: [
1137
+ {
1138
+ name: "",
1139
+ type: "uint256",
1140
+ internalType: "uint256"
1141
+ }
1142
+ ],
1143
+ stateMutability: "view"
1144
+ },
1145
+ {
1146
+ type: "function",
1147
+ name: "getDomainHash",
1148
+ inputs: [],
1149
+ outputs: [
1150
+ {
1151
+ name: "",
1152
+ type: "bytes32",
1153
+ internalType: "bytes32"
1154
+ }
1155
+ ],
1156
+ stateMutability: "view"
1157
+ },
1158
+ {
1159
+ type: "function",
1160
+ name: "getNonce",
1161
+ inputs: [
1162
+ {
1163
+ name: "_key",
1164
+ type: "uint192",
1165
+ internalType: "uint192"
1166
+ }
1167
+ ],
1168
+ outputs: [
1169
+ {
1170
+ name: "",
1171
+ type: "uint256",
1172
+ internalType: "uint256"
1173
+ }
1174
+ ],
1175
+ stateMutability: "view"
1176
+ },
1177
+ {
1178
+ type: "function",
1179
+ name: "getNonce",
1180
+ inputs: [],
1181
+ outputs: [
1182
+ {
1183
+ name: "",
1184
+ type: "uint256",
1185
+ internalType: "uint256"
1186
+ }
1187
+ ],
1188
+ stateMutability: "view"
1189
+ },
1190
+ {
1191
+ type: "function",
1192
+ name: "getPackedUserOperationHash",
1193
+ inputs: [
1194
+ {
1195
+ name: "_userOp",
1196
+ type: "tuple",
1197
+ internalType: "structPackedUserOperation",
1198
+ components: [
1199
+ {
1200
+ name: "sender",
1201
+ type: "address",
1202
+ internalType: "address"
1203
+ },
1204
+ {
1205
+ name: "nonce",
1206
+ type: "uint256",
1207
+ internalType: "uint256"
1208
+ },
1209
+ {
1210
+ name: "initCode",
1211
+ type: "bytes",
1212
+ internalType: "bytes"
1213
+ },
1214
+ {
1215
+ name: "callData",
1216
+ type: "bytes",
1217
+ internalType: "bytes"
1218
+ },
1219
+ {
1220
+ name: "accountGasLimits",
1221
+ type: "bytes32",
1222
+ internalType: "bytes32"
1223
+ },
1224
+ {
1225
+ name: "preVerificationGas",
1226
+ type: "uint256",
1227
+ internalType: "uint256"
1228
+ },
1229
+ {
1230
+ name: "gasFees",
1231
+ type: "bytes32",
1232
+ internalType: "bytes32"
1233
+ },
1234
+ {
1235
+ name: "paymasterAndData",
1236
+ type: "bytes",
1237
+ internalType: "bytes"
1238
+ },
1239
+ {
1240
+ name: "signature",
1241
+ type: "bytes",
1242
+ internalType: "bytes"
1243
+ }
1244
+ ]
1245
+ }
1246
+ ],
1247
+ outputs: [
1248
+ {
1249
+ name: "",
1250
+ type: "bytes32",
1251
+ internalType: "bytes32"
1252
+ }
1253
+ ],
1254
+ stateMutability: "view"
1255
+ },
1256
+ {
1257
+ type: "function",
1258
+ name: "getPackedUserOperationTypedDataHash",
1259
+ inputs: [
1260
+ {
1261
+ name: "_userOp",
1262
+ type: "tuple",
1263
+ internalType: "structPackedUserOperation",
1264
+ components: [
1265
+ {
1266
+ name: "sender",
1267
+ type: "address",
1268
+ internalType: "address"
1269
+ },
1270
+ {
1271
+ name: "nonce",
1272
+ type: "uint256",
1273
+ internalType: "uint256"
1274
+ },
1275
+ {
1276
+ name: "initCode",
1277
+ type: "bytes",
1278
+ internalType: "bytes"
1279
+ },
1280
+ {
1281
+ name: "callData",
1282
+ type: "bytes",
1283
+ internalType: "bytes"
1284
+ },
1285
+ {
1286
+ name: "accountGasLimits",
1287
+ type: "bytes32",
1288
+ internalType: "bytes32"
1289
+ },
1290
+ {
1291
+ name: "preVerificationGas",
1292
+ type: "uint256",
1293
+ internalType: "uint256"
1294
+ },
1295
+ {
1296
+ name: "gasFees",
1297
+ type: "bytes32",
1298
+ internalType: "bytes32"
1299
+ },
1300
+ {
1301
+ name: "paymasterAndData",
1302
+ type: "bytes",
1303
+ internalType: "bytes"
1304
+ },
1305
+ {
1306
+ name: "signature",
1307
+ type: "bytes",
1308
+ internalType: "bytes"
1309
+ }
1310
+ ]
1311
+ }
1312
+ ],
1313
+ outputs: [
1314
+ {
1315
+ name: "",
1316
+ type: "bytes32",
1317
+ internalType: "bytes32"
1318
+ }
1319
+ ],
1320
+ stateMutability: "view"
1321
+ },
1322
+ {
1323
+ type: "function",
1324
+ name: "isDelegationDisabled",
1325
+ inputs: [
1326
+ {
1327
+ name: "_delegationHash",
1328
+ type: "bytes32",
1329
+ internalType: "bytes32"
1330
+ }
1331
+ ],
1332
+ outputs: [
1333
+ {
1334
+ name: "",
1335
+ type: "bool",
1336
+ internalType: "bool"
1337
+ }
1338
+ ],
1339
+ stateMutability: "view"
1340
+ },
1341
+ {
1342
+ type: "function",
1343
+ name: "isValidSignature",
1344
+ inputs: [
1345
+ {
1346
+ name: "_hash",
1347
+ type: "bytes32",
1348
+ internalType: "bytes32"
1349
+ },
1350
+ {
1351
+ name: "_signature",
1352
+ type: "bytes",
1353
+ internalType: "bytes"
1354
+ }
1355
+ ],
1356
+ outputs: [
1357
+ {
1358
+ name: "magicValue_",
1359
+ type: "bytes4",
1360
+ internalType: "bytes4"
1361
+ }
1362
+ ],
1363
+ stateMutability: "view"
1364
+ },
1365
+ {
1366
+ type: "function",
1367
+ name: "onERC1155BatchReceived",
1368
+ inputs: [
1369
+ {
1370
+ name: "",
1371
+ type: "address",
1372
+ internalType: "address"
1373
+ },
1374
+ {
1375
+ name: "",
1376
+ type: "address",
1377
+ internalType: "address"
1378
+ },
1379
+ {
1380
+ name: "",
1381
+ type: "uint256[]",
1382
+ internalType: "uint256[]"
1383
+ },
1384
+ {
1385
+ name: "",
1386
+ type: "uint256[]",
1387
+ internalType: "uint256[]"
1388
+ },
1389
+ {
1390
+ name: "",
1391
+ type: "bytes",
1392
+ internalType: "bytes"
1393
+ }
1394
+ ],
1395
+ outputs: [
1396
+ {
1397
+ name: "",
1398
+ type: "bytes4",
1399
+ internalType: "bytes4"
1400
+ }
1401
+ ],
1402
+ stateMutability: "view"
1403
+ },
1404
+ {
1405
+ type: "function",
1406
+ name: "onERC1155Received",
1407
+ inputs: [
1408
+ {
1409
+ name: "",
1410
+ type: "address",
1411
+ internalType: "address"
1412
+ },
1413
+ {
1414
+ name: "",
1415
+ type: "address",
1416
+ internalType: "address"
1417
+ },
1418
+ {
1419
+ name: "",
1420
+ type: "uint256",
1421
+ internalType: "uint256"
1422
+ },
1423
+ {
1424
+ name: "",
1425
+ type: "uint256",
1426
+ internalType: "uint256"
1427
+ },
1428
+ {
1429
+ name: "",
1430
+ type: "bytes",
1431
+ internalType: "bytes"
1432
+ }
1433
+ ],
1434
+ outputs: [
1435
+ {
1436
+ name: "",
1437
+ type: "bytes4",
1438
+ internalType: "bytes4"
1439
+ }
1440
+ ],
1441
+ stateMutability: "view"
1442
+ },
1443
+ {
1444
+ type: "function",
1445
+ name: "onERC721Received",
1446
+ inputs: [
1447
+ {
1448
+ name: "",
1449
+ type: "address",
1450
+ internalType: "address"
1451
+ },
1452
+ {
1453
+ name: "",
1454
+ type: "address",
1455
+ internalType: "address"
1456
+ },
1457
+ {
1458
+ name: "",
1459
+ type: "uint256",
1460
+ internalType: "uint256"
1461
+ },
1462
+ {
1463
+ name: "",
1464
+ type: "bytes",
1465
+ internalType: "bytes"
1466
+ }
1467
+ ],
1468
+ outputs: [
1469
+ {
1470
+ name: "",
1471
+ type: "bytes4",
1472
+ internalType: "bytes4"
1473
+ }
1474
+ ],
1475
+ stateMutability: "view"
1476
+ },
1477
+ {
1478
+ type: "function",
1479
+ name: "redeemDelegations",
1480
+ inputs: [
1481
+ {
1482
+ name: "_permissionContexts",
1483
+ type: "bytes[]",
1484
+ internalType: "bytes[]"
1485
+ },
1486
+ {
1487
+ name: "_modes",
1488
+ type: "bytes32[]",
1489
+ internalType: "ModeCode[]"
1490
+ },
1491
+ {
1492
+ name: "_executionCallDatas",
1493
+ type: "bytes[]",
1494
+ internalType: "bytes[]"
1495
+ }
1496
+ ],
1497
+ outputs: [],
1498
+ stateMutability: "nonpayable"
1499
+ },
1500
+ {
1501
+ type: "function",
1502
+ name: "supportsExecutionMode",
1503
+ inputs: [
1504
+ {
1505
+ name: "_mode",
1506
+ type: "bytes32",
1507
+ internalType: "ModeCode"
1508
+ }
1509
+ ],
1510
+ outputs: [
1511
+ {
1512
+ name: "",
1513
+ type: "bool",
1514
+ internalType: "bool"
1515
+ }
1516
+ ],
1517
+ stateMutability: "view"
1518
+ },
1519
+ {
1520
+ type: "function",
1521
+ name: "supportsInterface",
1522
+ inputs: [
1523
+ {
1524
+ name: "_interfaceId",
1525
+ type: "bytes4",
1526
+ internalType: "bytes4"
1527
+ }
1528
+ ],
1529
+ outputs: [
1530
+ {
1531
+ name: "",
1532
+ type: "bool",
1533
+ internalType: "bool"
1534
+ }
1535
+ ],
1536
+ stateMutability: "view"
1537
+ },
1538
+ {
1539
+ type: "function",
1540
+ name: "validateUserOp",
1541
+ inputs: [
1542
+ {
1543
+ name: "_userOp",
1544
+ type: "tuple",
1545
+ internalType: "structPackedUserOperation",
1546
+ components: [
1547
+ {
1548
+ name: "sender",
1549
+ type: "address",
1550
+ internalType: "address"
1551
+ },
1552
+ {
1553
+ name: "nonce",
1554
+ type: "uint256",
1555
+ internalType: "uint256"
1556
+ },
1557
+ {
1558
+ name: "initCode",
1559
+ type: "bytes",
1560
+ internalType: "bytes"
1561
+ },
1562
+ {
1563
+ name: "callData",
1564
+ type: "bytes",
1565
+ internalType: "bytes"
1566
+ },
1567
+ {
1568
+ name: "accountGasLimits",
1569
+ type: "bytes32",
1570
+ internalType: "bytes32"
1571
+ },
1572
+ {
1573
+ name: "preVerificationGas",
1574
+ type: "uint256",
1575
+ internalType: "uint256"
1576
+ },
1577
+ {
1578
+ name: "gasFees",
1579
+ type: "bytes32",
1580
+ internalType: "bytes32"
1581
+ },
1582
+ {
1583
+ name: "paymasterAndData",
1584
+ type: "bytes",
1585
+ internalType: "bytes"
1586
+ },
1587
+ {
1588
+ name: "signature",
1589
+ type: "bytes",
1590
+ internalType: "bytes"
1591
+ }
1592
+ ]
1593
+ },
1594
+ {
1595
+ name: "",
1596
+ type: "bytes32",
1597
+ internalType: "bytes32"
1598
+ },
1599
+ {
1600
+ name: "_missingAccountFunds",
1601
+ type: "uint256",
1602
+ internalType: "uint256"
1603
+ }
1604
+ ],
1605
+ outputs: [
1606
+ {
1607
+ name: "validationData_",
1608
+ type: "uint256",
1609
+ internalType: "uint256"
1610
+ }
1611
+ ],
1612
+ stateMutability: "nonpayable"
1613
+ },
1614
+ {
1615
+ type: "function",
1616
+ name: "withdrawDeposit",
1617
+ inputs: [
1618
+ {
1619
+ name: "_withdrawAddress",
1620
+ type: "address",
1621
+ internalType: "addresspayable"
1622
+ },
1623
+ {
1624
+ name: "_withdrawAmount",
1625
+ type: "uint256",
1626
+ internalType: "uint256"
1627
+ }
1628
+ ],
1629
+ outputs: [],
1630
+ stateMutability: "nonpayable"
1631
+ },
1632
+ {
1633
+ type: "event",
1634
+ name: "EIP712DomainChanged",
1635
+ inputs: [],
1636
+ anonymous: false
1637
+ },
1638
+ {
1639
+ type: "event",
1640
+ name: "SentPrefund",
1641
+ inputs: [
1642
+ {
1643
+ name: "sender",
1644
+ type: "address",
1645
+ indexed: true,
1646
+ internalType: "address"
1647
+ },
1648
+ {
1649
+ name: "amount",
1650
+ type: "uint256",
1651
+ indexed: false,
1652
+ internalType: "uint256"
1653
+ },
1654
+ {
1655
+ name: "success",
1656
+ type: "bool",
1657
+ indexed: false,
1658
+ internalType: "bool"
1659
+ }
1660
+ ],
1661
+ anonymous: false
1662
+ },
1663
+ {
1664
+ type: "event",
1665
+ name: "SetDelegationManager",
1666
+ inputs: [
1667
+ {
1668
+ name: "newDelegationManager",
1669
+ type: "address",
1670
+ indexed: true,
1671
+ internalType: "contractIDelegationManager"
1672
+ }
1673
+ ],
1674
+ anonymous: false
1675
+ },
1676
+ {
1677
+ type: "event",
1678
+ name: "SetEntryPoint",
1679
+ inputs: [
1680
+ {
1681
+ name: "entryPoint",
1682
+ type: "address",
1683
+ indexed: true,
1684
+ internalType: "contractIEntryPoint"
1685
+ }
1686
+ ],
1687
+ anonymous: false
1688
+ },
1689
+ {
1690
+ type: "event",
1691
+ name: "TryExecuteUnsuccessful",
1692
+ inputs: [
1693
+ {
1694
+ name: "batchExecutionindex",
1695
+ type: "uint256",
1696
+ indexed: false,
1697
+ internalType: "uint256"
1698
+ },
1699
+ {
1700
+ name: "result",
1701
+ type: "bytes",
1702
+ indexed: false,
1703
+ internalType: "bytes"
1704
+ }
1705
+ ],
1706
+ anonymous: false
1707
+ },
1708
+ {
1709
+ type: "error",
1710
+ name: "ECDSAInvalidSignature",
1711
+ inputs: []
1712
+ },
1713
+ {
1714
+ type: "error",
1715
+ name: "ECDSAInvalidSignatureLength",
1716
+ inputs: [
1717
+ {
1718
+ name: "length",
1719
+ type: "uint256",
1720
+ internalType: "uint256"
1721
+ }
1722
+ ]
1723
+ },
1724
+ {
1725
+ type: "error",
1726
+ name: "ECDSAInvalidSignatureS",
1727
+ inputs: [
1728
+ {
1729
+ name: "s",
1730
+ type: "bytes32",
1731
+ internalType: "bytes32"
1732
+ }
1733
+ ]
1734
+ },
1735
+ {
1736
+ type: "error",
1737
+ name: "ExecutionFailed",
1738
+ inputs: []
1739
+ },
1740
+ {
1741
+ type: "error",
1742
+ name: "InvalidEIP712NameLength",
1743
+ inputs: []
1744
+ },
1745
+ {
1746
+ type: "error",
1747
+ name: "InvalidEIP712VersionLength",
1748
+ inputs: []
1749
+ },
1750
+ {
1751
+ type: "error",
1752
+ name: "InvalidShortString",
1753
+ inputs: []
1754
+ },
1755
+ {
1756
+ type: "error",
1757
+ name: "NotDelegationManager",
1758
+ inputs: []
1759
+ },
1760
+ {
1761
+ type: "error",
1762
+ name: "NotEntryPoint",
1763
+ inputs: []
1764
+ },
1765
+ {
1766
+ type: "error",
1767
+ name: "NotEntryPointOrSelf",
1768
+ inputs: []
1769
+ },
1770
+ {
1771
+ type: "error",
1772
+ name: "NotSelf",
1773
+ inputs: []
1774
+ },
1775
+ {
1776
+ type: "error",
1777
+ name: "StringTooLong",
1778
+ inputs: [
1779
+ {
1780
+ name: "str",
1781
+ type: "string",
1782
+ internalType: "string"
1783
+ }
1784
+ ]
1785
+ },
1786
+ {
1787
+ type: "error",
1788
+ name: "UnauthorizedCallContext",
1789
+ inputs: []
1790
+ },
1791
+ {
1792
+ type: "error",
1793
+ name: "UnsupportedCallType",
1794
+ inputs: [
1795
+ {
1796
+ name: "callType",
1797
+ type: "bytes1",
1798
+ internalType: "CallType"
1799
+ }
1800
+ ]
1801
+ },
1802
+ {
1803
+ type: "error",
1804
+ name: "UnsupportedExecType",
1805
+ inputs: [
1806
+ {
1807
+ name: "execType",
1808
+ type: "bytes1",
1809
+ internalType: "ExecType"
1810
+ }
1811
+ ]
1812
+ }
1813
+ ];
1814
+
1815
+ // src/client/common/contract/caller.ts
1816
+ var import_viem3 = require("viem");
1817
+
1818
+ // src/client/common/contract/eip7702.ts
1819
+ var EXECUTE_BATCH_MODE = "0x0100000000000000000000000000000000000000000000000000000000000000";
1820
+ function encodeExecuteBatchData(executions) {
1821
+ const encodedExecutions = (0, import_viem4.encodeAbiParameters)(
1822
+ [
1823
+ {
1824
+ type: "tuple[]",
1825
+ components: [
1826
+ { name: "target", type: "address" },
1827
+ { name: "value", type: "uint256" },
1828
+ { name: "callData", type: "bytes" }
1829
+ ]
1830
+ }
1831
+ ],
1832
+ [executions]
1833
+ );
1834
+ return (0, import_viem4.encodeFunctionData)({
1835
+ abi: ERC7702Delegator_default,
1836
+ functionName: "execute",
1837
+ args: [EXECUTE_BATCH_MODE, encodedExecutions]
1838
+ });
1839
+ }
1840
+ async function checkERC7702Delegation(publicClient, account, delegatorAddress) {
1841
+ const code = await publicClient.getCode({ address: account });
1842
+ if (!code) {
1843
+ return false;
1844
+ }
1845
+ const expectedCode = `0xef0100${delegatorAddress.slice(2)}`;
1846
+ return code.toLowerCase() === expectedCode.toLowerCase();
1847
+ }
1848
+ async function executeBatch(options, logger = noopLogger) {
1849
+ const {
1850
+ walletClient,
1851
+ publicClient,
1852
+ environmentConfig,
1853
+ executions,
1854
+ pendingMessage,
1855
+ gas,
1856
+ authorizationList: providedAuthList
1857
+ } = options;
1858
+ const account = walletClient.account;
1859
+ if (!account) {
1860
+ throw new Error("Wallet client must have an account");
1861
+ }
1862
+ const chain = walletClient.chain;
1863
+ if (!chain) {
1864
+ throw new Error("Wallet client must have a chain");
1865
+ }
1866
+ const executeBatchData = encodeExecuteBatchData(executions);
1867
+ let authorizationList = providedAuthList || [];
1868
+ if (authorizationList.length === 0) {
1869
+ const isDelegated = await checkERC7702Delegation(
1870
+ publicClient,
1871
+ account.address,
1872
+ environmentConfig.erc7702DelegatorAddress
1873
+ );
1874
+ if (!isDelegated) {
1875
+ const transactionNonce = await publicClient.getTransactionCount({
1876
+ address: account.address,
1877
+ blockTag: "pending"
1878
+ });
1879
+ const chainId = await publicClient.getChainId();
1880
+ const authorizationNonce = transactionNonce + 1;
1881
+ logger.debug("Using wallet client signing for EIP-7702 authorization");
1882
+ const signedAuthorization = await walletClient.signAuthorization({
1883
+ account,
1884
+ contractAddress: environmentConfig.erc7702DelegatorAddress,
1885
+ chainId,
1886
+ nonce: Number(authorizationNonce)
1887
+ });
1888
+ authorizationList = [signedAuthorization];
1889
+ }
1890
+ }
1891
+ if (pendingMessage) {
1892
+ logger.info(pendingMessage);
1893
+ }
1894
+ const txRequest = {
1895
+ account: walletClient.account,
1896
+ chain,
1897
+ to: account.address,
1898
+ data: executeBatchData,
1899
+ value: 0n
1900
+ };
1901
+ if (authorizationList.length > 0) {
1902
+ txRequest.authorizationList = authorizationList;
1903
+ }
1904
+ if (gas?.gasLimit) {
1905
+ txRequest.gas = gas.gasLimit;
1906
+ }
1907
+ if (gas?.maxFeePerGas) {
1908
+ txRequest.maxFeePerGas = gas.maxFeePerGas;
1909
+ }
1910
+ if (gas?.maxPriorityFeePerGas) {
1911
+ txRequest.maxPriorityFeePerGas = gas.maxPriorityFeePerGas;
1912
+ }
1913
+ const hash = await walletClient.sendTransaction(txRequest);
1914
+ logger.info(`Transaction sent: ${hash}`);
1915
+ const receipt = await publicClient.waitForTransactionReceipt({ hash });
1916
+ if (receipt.status === "reverted") {
1917
+ let revertReason = "Unknown reason";
1918
+ try {
1919
+ await publicClient.call({
1920
+ to: account.address,
1921
+ data: executeBatchData,
1922
+ account: account.address
1923
+ });
1924
+ } catch (callError) {
1925
+ if (callError.data) {
1926
+ try {
1927
+ const decoded = (0, import_viem4.decodeErrorResult)({
1928
+ abi: ERC7702Delegator_default,
1929
+ data: callError.data
1930
+ });
1931
+ revertReason = `${decoded.errorName}: ${JSON.stringify(decoded.args)}`;
1932
+ } catch {
1933
+ revertReason = callError.message || "Unknown reason";
1934
+ }
1935
+ } else {
1936
+ revertReason = callError.message || "Unknown reason";
1937
+ }
1938
+ }
1939
+ throw new Error(`Transaction reverted: ${hash}. Reason: ${revertReason}`);
1940
+ }
1941
+ return hash;
1942
+ }
1943
+
1944
+ // src/client/common/abis/USDCCredits.json
1945
+ var USDCCredits_default = [
1946
+ {
1947
+ type: "function",
1948
+ name: "purchaseCreditsFor",
1949
+ stateMutability: "nonpayable",
1950
+ inputs: [
1951
+ { name: "amount", type: "uint256" },
1952
+ { name: "account", type: "address" }
1953
+ ],
1954
+ outputs: []
1955
+ },
1956
+ {
1957
+ type: "function",
1958
+ name: "purchaseCredits",
1959
+ stateMutability: "nonpayable",
1960
+ inputs: [
1961
+ { name: "amount", type: "uint256" }
1962
+ ],
1963
+ outputs: []
1964
+ },
1965
+ {
1966
+ type: "function",
1967
+ name: "usdc",
1968
+ stateMutability: "view",
1969
+ inputs: [],
1970
+ outputs: [
1971
+ { name: "", type: "address" }
1972
+ ]
1973
+ },
1974
+ {
1975
+ type: "function",
1976
+ name: "minimumPurchase",
1977
+ stateMutability: "view",
1978
+ inputs: [],
1979
+ outputs: [
1980
+ { name: "", type: "uint256" }
1981
+ ]
1982
+ },
1983
+ {
1984
+ type: "event",
1985
+ name: "CreditsPurchased",
1986
+ inputs: [
1987
+ { name: "purchaser", type: "address", indexed: true },
1988
+ { name: "account", type: "address", indexed: true },
1989
+ { name: "amount", type: "uint256", indexed: false }
1990
+ ]
1991
+ }
1992
+ ];
1993
+
1994
+ // src/client/common/abis/ERC20.json
1995
+ var ERC20_default = [
1996
+ {
1997
+ type: "function",
1998
+ name: "approve",
1999
+ stateMutability: "nonpayable",
2000
+ inputs: [
2001
+ { name: "spender", type: "address" },
2002
+ { name: "amount", type: "uint256" }
2003
+ ],
2004
+ outputs: [
2005
+ { name: "", type: "bool" }
2006
+ ]
2007
+ },
2008
+ {
2009
+ type: "function",
2010
+ name: "balanceOf",
2011
+ stateMutability: "view",
2012
+ inputs: [
2013
+ { name: "account", type: "address" }
2014
+ ],
2015
+ outputs: [
2016
+ { name: "", type: "uint256" }
2017
+ ]
2018
+ },
2019
+ {
2020
+ type: "function",
2021
+ name: "allowance",
2022
+ stateMutability: "view",
2023
+ inputs: [
2024
+ { name: "owner", type: "address" },
2025
+ { name: "spender", type: "address" }
2026
+ ],
2027
+ outputs: [
2028
+ { name: "", type: "uint256" }
2029
+ ]
2030
+ }
2031
+ ];
2032
+
735
2033
  // src/client/modules/billing/index.ts
736
2034
  function createBillingModule(config) {
737
- const { verbose = false, skipTelemetry = false, walletClient } = config;
2035
+ const { verbose = false, skipTelemetry = false, walletClient, publicClient, environment } = config;
738
2036
  if (!walletClient.account) {
739
2037
  throw new Error("WalletClient must have an account attached");
740
2038
  }
@@ -742,8 +2040,85 @@ function createBillingModule(config) {
742
2040
  const logger = getLogger(verbose);
743
2041
  const billingEnvConfig = getBillingEnvironmentConfig(getBuildType());
744
2042
  const billingApi = new BillingApiClient(billingEnvConfig, walletClient);
745
- return {
2043
+ const environmentConfig = getEnvironmentConfig(environment);
2044
+ const usdcCreditsAddress = environmentConfig.usdcCreditsAddress;
2045
+ if (!usdcCreditsAddress) {
2046
+ throw new Error(`USDCCredits contract address not configured for environment "${environment}"`);
2047
+ }
2048
+ const module2 = {
746
2049
  address,
2050
+ async getTopUpInfo() {
2051
+ const usdcAddress = await publicClient.readContract({
2052
+ address: usdcCreditsAddress,
2053
+ abi: USDCCredits_default,
2054
+ functionName: "usdc"
2055
+ });
2056
+ const [minimumPurchase, usdcBalance, currentAllowance] = await Promise.all([
2057
+ publicClient.readContract({
2058
+ address: usdcCreditsAddress,
2059
+ abi: USDCCredits_default,
2060
+ functionName: "minimumPurchase"
2061
+ }),
2062
+ publicClient.readContract({
2063
+ address: usdcAddress,
2064
+ abi: ERC20_default,
2065
+ functionName: "balanceOf",
2066
+ args: [address]
2067
+ }),
2068
+ publicClient.readContract({
2069
+ address: usdcAddress,
2070
+ abi: ERC20_default,
2071
+ functionName: "allowance",
2072
+ args: [address, usdcCreditsAddress]
2073
+ })
2074
+ ]);
2075
+ return { usdcAddress, minimumPurchase, usdcBalance, currentAllowance };
2076
+ },
2077
+ async topUp(opts) {
2078
+ return withSDKTelemetry(
2079
+ {
2080
+ functionName: "topUp",
2081
+ skipTelemetry,
2082
+ properties: { amount: opts.amount.toString() }
2083
+ },
2084
+ async () => {
2085
+ const targetAccount = opts.account ?? address;
2086
+ const { usdcAddress, currentAllowance } = await module2.getTopUpInfo();
2087
+ const executions = [];
2088
+ if (currentAllowance < opts.amount) {
2089
+ executions.push({
2090
+ target: usdcAddress,
2091
+ value: 0n,
2092
+ callData: (0, import_viem5.encodeFunctionData)({
2093
+ abi: ERC20_default,
2094
+ functionName: "approve",
2095
+ args: [usdcCreditsAddress, opts.amount]
2096
+ })
2097
+ });
2098
+ }
2099
+ executions.push({
2100
+ target: usdcCreditsAddress,
2101
+ value: 0n,
2102
+ callData: (0, import_viem5.encodeFunctionData)({
2103
+ abi: USDCCredits_default,
2104
+ functionName: "purchaseCreditsFor",
2105
+ args: [opts.amount, targetAccount]
2106
+ })
2107
+ });
2108
+ const txHash = await executeBatch(
2109
+ {
2110
+ walletClient,
2111
+ publicClient,
2112
+ environmentConfig,
2113
+ executions,
2114
+ pendingMessage: "Submitting credit purchase..."
2115
+ },
2116
+ logger
2117
+ );
2118
+ return { txHash, walletAddress: address };
2119
+ }
2120
+ );
2121
+ },
747
2122
  async subscribe(opts) {
748
2123
  return withSDKTelemetry(
749
2124
  {
@@ -830,6 +2205,7 @@ function createBillingModule(config) {
830
2205
  );
831
2206
  }
832
2207
  };
2208
+ return module2;
833
2209
  }
834
2210
  // Annotate the CommonJS export names for ESM import in node:
835
2211
  0 && (module.exports = {