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