@actalink/commonlib 0.0.6 → 0.0.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.cjs CHANGED
@@ -58,6 +58,7 @@ var __async = (__this, __arguments, generator) => {
58
58
  var index_exports = {};
59
59
  __export(index_exports, {
60
60
  ActaAccount: () => ActaAccount,
61
+ ActaBilling: () => ActaBilling,
61
62
  ActaDeposit: () => ActaDeposit,
62
63
  ConnectorType: () => ConnectorType,
63
64
  HttpMethod: () => HttpMethod,
@@ -83,6 +84,8 @@ __export(index_exports, {
83
84
  bscUSDT: () => bscUSDT,
84
85
  bscWBNB: () => bscWBNB,
85
86
  bytesToBase64: () => bytesToBase64,
87
+ createBillingCheckoutSession: () => createBillingCheckoutSession,
88
+ createBillingSessionAPICall: () => createBillingSessionAPICall,
86
89
  createPolicyFromParams: () => createPolicyFromParams,
87
90
  createSessionAPICall: () => createSessionAPICall,
88
91
  decodeParamsFromInitCode: () => decodeParamsFromInitCode,
@@ -95,6 +98,8 @@ __export(index_exports, {
95
98
  ethereumUSDT: () => ethereumUSDT,
96
99
  ethereumWETH: () => ethereumWETH,
97
100
  executeSinglePaymentAPICall: () => executeSinglePaymentAPICall,
101
+ fetchBillingSessionDetails: () => fetchBillingSessionDetails,
102
+ getBillingPaymentSessionDetails: () => getBillingPaymentSessionDetails,
98
103
  getChainById: () => getChainById,
99
104
  getChainExplorerByChainId: () => getChainExplorerByChainId,
100
105
  getPeriodInterval: () => getPeriodInterval,
@@ -611,7 +616,7 @@ function getTokenByChainIdAndAddress(chainId, address) {
611
616
  var import_viem6 = require("viem");
612
617
 
613
618
  // src/account.ts
614
- var import_viem4 = require("viem");
619
+ var import_viem5 = require("viem");
615
620
  var import_account_abstraction2 = require("viem/account-abstraction");
616
621
  var import_sdk2 = require("@zerodev/sdk");
617
622
  var import_constants = require("@zerodev/sdk/constants");
@@ -729,18 +734,153 @@ var ViemClient = class {
729
734
  // src/utils.ts
730
735
  var import_sdk = require("@zerodev/sdk");
731
736
  var import_accounts = require("@zerodev/sdk/accounts");
732
- var import_viem3 = require("viem");
737
+ var import_viem4 = require("viem");
733
738
  var import_accounts2 = require("viem/accounts");
734
739
  var import_actions = require("viem/actions");
735
740
  var import_utils = require("viem/utils");
736
741
  var import_account_abstraction = require("viem/account-abstraction");
737
742
  var import_policies = require("@zerodev/permissions/policies");
738
743
  var import_semver = require("semver");
744
+
745
+ // src/api.ts
746
+ var import_viem3 = require("viem");
747
+ var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
748
+ HttpMethod2["Get"] = "get";
749
+ HttpMethod2["Post"] = "post";
750
+ HttpMethod2["Delete"] = "delete";
751
+ HttpMethod2["Update"] = "update";
752
+ return HttpMethod2;
753
+ })(HttpMethod || {});
754
+ function sendRequest(_0) {
755
+ return __async(this, arguments, function* ({
756
+ url,
757
+ method,
758
+ body,
759
+ headers = {}
760
+ }) {
761
+ var _a;
762
+ const response = yield fetch(url, {
763
+ method,
764
+ headers: __spreadProps(__spreadValues({}, headers), {
765
+ Accept: "application/json",
766
+ "Content-Type": "application/json"
767
+ }),
768
+ body: JSON.stringify(body)
769
+ });
770
+ let jsonResponse;
771
+ const res = yield response.json();
772
+ if (!response.ok) {
773
+ jsonResponse = {
774
+ error: {
775
+ code: response.status,
776
+ message: response.statusText
777
+ },
778
+ data: void 0
779
+ };
780
+ return jsonResponse;
781
+ }
782
+ if (!res) {
783
+ jsonResponse = {
784
+ error: {
785
+ code: 400,
786
+ message: "No response received."
787
+ },
788
+ data: void 0
789
+ };
790
+ return jsonResponse;
791
+ }
792
+ if (res == null ? void 0 : res.error) {
793
+ jsonResponse = {
794
+ error: {
795
+ code: response.status,
796
+ message: res.error
797
+ },
798
+ data: void 0
799
+ };
800
+ return jsonResponse;
801
+ }
802
+ jsonResponse = {
803
+ data: res.data,
804
+ message: (_a = res.message) != null ? _a : "Success",
805
+ error: void 0
806
+ };
807
+ return jsonResponse;
808
+ });
809
+ }
810
+ function createSessionAPICall(url, sessionBodyParams) {
811
+ return __async(this, null, function* () {
812
+ const response = yield sendRequest({
813
+ url,
814
+ method: "post" /* Post */,
815
+ body: sessionBodyParams
816
+ });
817
+ return response.data;
818
+ });
819
+ }
820
+ function verifySessionAPICall(url, sessionId) {
821
+ return __async(this, null, function* () {
822
+ const response = yield sendRequest({
823
+ url,
824
+ method: "get" /* Get */
825
+ });
826
+ return response.data;
827
+ });
828
+ }
829
+ function scheduleRecurringPaymentsAPICall(url, params) {
830
+ return __async(this, null, function* () {
831
+ const parsedParams = __spreadProps(__spreadValues({}, params), {
832
+ amount: (0, import_viem3.toHex)(params.amount)
833
+ });
834
+ const response = yield sendRequest({
835
+ url,
836
+ method: "post" /* Post */,
837
+ body: parsedParams
838
+ });
839
+ return response.data;
840
+ });
841
+ }
842
+ function createBillingSessionAPICall(url, sessionBodyParams) {
843
+ return __async(this, null, function* () {
844
+ const response = yield sendRequest({
845
+ url,
846
+ method: "post" /* Post */,
847
+ body: sessionBodyParams
848
+ });
849
+ return response.data;
850
+ });
851
+ }
852
+ function fetchBillingSessionDetails(url) {
853
+ return __async(this, null, function* () {
854
+ const response = yield sendRequest({
855
+ url,
856
+ method: "get" /* Get */
857
+ });
858
+ return response.data;
859
+ });
860
+ }
861
+ function executeSinglePaymentAPICall(url, userOperation, paymentParams, serviceParams) {
862
+ return __async(this, null, function* () {
863
+ const params = {
864
+ userOperation,
865
+ paymentParams,
866
+ serviceParams
867
+ };
868
+ const response = yield sendRequest({
869
+ url,
870
+ method: "post" /* Post */,
871
+ body: params
872
+ });
873
+ return response.data;
874
+ });
875
+ }
876
+
877
+ // src/utils.ts
739
878
  var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
879
+ var billingServiceUrl = "http://localhost:4000/billing/v1/";
740
880
  var toSignerId = (signer) => {
741
- return (0, import_viem3.encodeAbiParameters)(
881
+ return (0, import_viem4.encodeAbiParameters)(
742
882
  [{ name: "signerData", type: "bytes" }],
743
- [(0, import_viem3.concat)([signer.signerContractAddress, signer.getSignerData()])]
883
+ [(0, import_viem4.concat)([signer.signerContractAddress, signer.getSignerData()])]
744
884
  );
745
885
  };
746
886
  function toECDSASigner(_0) {
@@ -777,11 +917,11 @@ function toECDSASigner(_0) {
777
917
  });
778
918
  }
779
919
  var toPolicyId = (policies) => {
780
- return (0, import_viem3.encodeAbiParameters)(
920
+ return (0, import_viem4.encodeAbiParameters)(
781
921
  [{ name: "policiesData", type: "bytes[]" }],
782
922
  [
783
923
  policies.map(
784
- (policy) => (0, import_viem3.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
924
+ (policy) => (0, import_viem4.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
785
925
  )
786
926
  ]
787
927
  );
@@ -799,38 +939,38 @@ function toPermissionValidator(_0, _1) {
799
939
  throw new Error("Only EntryPoint 0.7 is supported");
800
940
  }
801
941
  const getEnableData = (_kernelAccountAddress) => __async(null, null, function* () {
802
- const enableData = (0, import_viem3.encodeAbiParameters)(
942
+ const enableData = (0, import_viem4.encodeAbiParameters)(
803
943
  [{ name: "policyAndSignerData", type: "bytes[]" }],
804
944
  [
805
945
  [
806
946
  ...policies.map(
807
- (policy) => (0, import_viem3.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
947
+ (policy) => (0, import_viem4.concat)([policy.getPolicyInfoInBytes(), policy.getPolicyData()])
808
948
  ),
809
- (0, import_viem3.concat)([flag, signer.signerContractAddress, signer.getSignerData()])
949
+ (0, import_viem4.concat)([flag, signer.signerContractAddress, signer.getSignerData()])
810
950
  ]
811
951
  ]
812
952
  );
813
953
  return enableData;
814
954
  });
815
955
  const getPermissionId = () => {
816
- const pIdData = (0, import_viem3.encodeAbiParameters)(
956
+ const pIdData = (0, import_viem4.encodeAbiParameters)(
817
957
  [{ name: "policyAndSignerData", type: "bytes[]" }],
818
958
  [[toPolicyId(policies), flag, toSignerId(signer)]]
819
959
  );
820
- return (0, import_viem3.slice)((0, import_viem3.keccak256)(pIdData), 0, 4);
960
+ return (0, import_viem4.slice)((0, import_viem4.keccak256)(pIdData), 0, 4);
821
961
  };
822
962
  return __spreadProps(__spreadValues({}, signer.account), {
823
963
  supportedKernelVersions: ">=0.3.0",
824
964
  validatorType: "PERMISSION",
825
- address: import_viem3.zeroAddress,
965
+ address: import_viem4.zeroAddress,
826
966
  source: "PermissionValidator",
827
967
  getEnableData,
828
968
  getIdentifier: getPermissionId,
829
969
  signMessage: (_02) => __async(null, [_02], function* ({ message }) {
830
- return (0, import_viem3.concat)(["0xff", yield signer.account.signMessage({ message })]);
970
+ return (0, import_viem4.concat)(["0xff", yield signer.account.signMessage({ message })]);
831
971
  }),
832
972
  signTypedData: (typedData) => __async(null, null, function* () {
833
- return (0, import_viem3.concat)(["0xff", yield signer.account.signTypedData(typedData)]);
973
+ return (0, import_viem4.concat)(["0xff", yield signer.account.signTypedData(typedData)]);
834
974
  }),
835
975
  signUserOperation: (userOperation) => __async(null, null, function* () {
836
976
  const userOpHash = (0, import_account_abstraction.getUserOperationHash)({
@@ -844,7 +984,7 @@ function toPermissionValidator(_0, _1) {
844
984
  const signature = yield signer.account.signMessage({
845
985
  message: { raw: userOpHash }
846
986
  });
847
- return (0, import_viem3.concat)(["0xff", signature]);
987
+ return (0, import_viem4.concat)(["0xff", signature]);
848
988
  }),
849
989
  getNonceKey(_accountAddress, customNonceKey) {
850
990
  return __async(this, null, function* () {
@@ -856,7 +996,7 @@ function toPermissionValidator(_0, _1) {
856
996
  },
857
997
  getStubSignature(_userOperation) {
858
998
  return __async(this, null, function* () {
859
- return (0, import_viem3.concat)(["0xff", signer.getDummySignature()]);
999
+ return (0, import_viem4.concat)(["0xff", signer.getDummySignature()]);
860
1000
  });
861
1001
  },
862
1002
  getPluginSerializationParams: () => {
@@ -1018,12 +1158,12 @@ var decodeParamsFromInitCode = (initCode, kernelVersion) => {
1018
1158
  };
1019
1159
  }
1020
1160
  try {
1021
- deployWithFactoryFunctionData = (0, import_viem3.decodeFunctionData)({
1161
+ deployWithFactoryFunctionData = (0, import_viem4.decodeFunctionData)({
1022
1162
  abi: import_sdk.KernelFactoryStakerAbi,
1023
1163
  data: initCode
1024
1164
  });
1025
1165
  } catch (error) {
1026
- deployWithFactoryFunctionData = (0, import_viem3.decodeFunctionData)({
1166
+ deployWithFactoryFunctionData = (0, import_viem4.decodeFunctionData)({
1027
1167
  abi: import_sdk.KernelV3FactoryAbi,
1028
1168
  data: initCode
1029
1169
  });
@@ -1034,12 +1174,12 @@ var decodeParamsFromInitCode = (initCode, kernelVersion) => {
1034
1174
  index = BigInt(deployWithFactoryFunctionData.args[2]);
1035
1175
  let initializeFunctionData;
1036
1176
  if (kernelVersion === "0.3.0") {
1037
- initializeFunctionData = (0, import_viem3.decodeFunctionData)({
1177
+ initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1038
1178
  abi: import_sdk.KernelV3AccountAbi,
1039
1179
  data: deployWithFactoryFunctionData.args[1]
1040
1180
  });
1041
1181
  } else {
1042
- initializeFunctionData = (0, import_viem3.decodeFunctionData)({
1182
+ initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1043
1183
  abi: import_sdk.KernelV3_1AccountAbi,
1044
1184
  data: deployWithFactoryFunctionData.args[1]
1045
1185
  });
@@ -1057,12 +1197,12 @@ var decodeParamsFromInitCode = (initCode, kernelVersion) => {
1057
1197
  index = BigInt(deployWithFactoryFunctionData.args[1]);
1058
1198
  let initializeFunctionData;
1059
1199
  if (kernelVersion === "0.3.0") {
1060
- initializeFunctionData = (0, import_viem3.decodeFunctionData)({
1200
+ initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1061
1201
  abi: import_sdk.KernelV3AccountAbi,
1062
1202
  data: deployWithFactoryFunctionData.args[0]
1063
1203
  });
1064
1204
  } else {
1065
- initializeFunctionData = (0, import_viem3.decodeFunctionData)({
1205
+ initializeFunctionData = (0, import_viem4.decodeFunctionData)({
1066
1206
  abi: import_sdk.KernelV3_1AccountAbi,
1067
1207
  data: deployWithFactoryFunctionData.args[0]
1068
1208
  });
@@ -1097,6 +1237,33 @@ var getPeriodInterval = (periodUnit) => {
1097
1237
  throw new Error("Invalid period unit");
1098
1238
  }
1099
1239
  };
1240
+ var createBillingCheckoutSession = (serviceSessionparams) => __async(null, null, function* () {
1241
+ try {
1242
+ const sessionData = yield createBillingSessionAPICall(
1243
+ `${billingServiceUrl}paysession/create`,
1244
+ {
1245
+ paylinkId: serviceSessionparams.paylinkId
1246
+ }
1247
+ );
1248
+ if (sessionData) {
1249
+ return sessionData.checkoutSessionId;
1250
+ }
1251
+ } catch (error) {
1252
+ if (error instanceof Error) {
1253
+ throw new Error(error.message);
1254
+ }
1255
+ throw new Error("Failed to create deposit session.");
1256
+ }
1257
+ });
1258
+ var getBillingPaymentSessionDetails = (serviceSessionparams) => __async(null, null, function* () {
1259
+ if (!serviceSessionparams.checkoutSessionId || serviceSessionparams.checkoutSessionId === "") {
1260
+ throw new Error("checkout session ID is required.");
1261
+ }
1262
+ const sessionData = yield fetchBillingSessionDetails(
1263
+ `${billingServiceUrl}paysession?checkoutSessionId=${serviceSessionparams.checkoutSessionId}`
1264
+ );
1265
+ return sessionData;
1266
+ });
1100
1267
 
1101
1268
  // src/account.ts
1102
1269
  var import_policies2 = require("@zerodev/permissions/policies");
@@ -1130,18 +1297,18 @@ var ActaAccount = class {
1130
1297
  const account = yield this.createAccount();
1131
1298
  const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1132
1299
  const paymasterClient = (0, import_account_abstraction2.createPaymasterClient)({
1133
- transport: (0, import_viem4.http)(getPimlicoRpcByChainId(this.chainId))
1300
+ transport: (0, import_viem5.http)(getPimlicoRpcByChainId(this.chainId))
1134
1301
  });
1135
1302
  const pimlicoClient = (0, import_pimlico.createPimlicoClient)({
1136
1303
  chain: getChainById(this.chainId),
1137
- transport: (0, import_viem4.http)(getPimlicoRpcByChainId(this.chainId)),
1304
+ transport: (0, import_viem5.http)(getPimlicoRpcByChainId(this.chainId)),
1138
1305
  entryPoint
1139
1306
  });
1140
1307
  const accountClient = (0, import_permissionless.createSmartAccountClient)({
1141
1308
  account,
1142
1309
  chain: getChainById(this.chainId),
1143
1310
  paymaster: paymasterClient,
1144
- bundlerTransport: (0, import_viem4.http)(getPimlicoRpcByChainId(this.chainId)),
1311
+ bundlerTransport: (0, import_viem5.http)(getPimlicoRpcByChainId(this.chainId)),
1145
1312
  userOperation: {
1146
1313
  estimateFeesPerGas: () => __async(this, null, function* () {
1147
1314
  return (yield pimlicoClient.getUserOperationGasPrice()).fast;
@@ -1182,18 +1349,18 @@ var ActaAccount = class {
1182
1349
  const userOperation = yield accountClient.prepareUserOperation({
1183
1350
  calls: [
1184
1351
  {
1185
- to: (0, import_viem4.getAddress)(token2.address),
1186
- abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1352
+ to: (0, import_viem5.getAddress)(token2.address),
1353
+ abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1187
1354
  functionName: "transferFrom",
1188
1355
  args: [
1189
1356
  fromAddress,
1190
- "0x061BA68bc8208F4AddBeE86F74F17D77129cCF70",
1357
+ "0xC4910E5ec82Da0A41aF9C6360b7A1f531e1e37B0",
1191
1358
  BigInt(0)
1192
1359
  ]
1193
1360
  },
1194
1361
  {
1195
- to: (0, import_viem4.getAddress)(token2.address),
1196
- abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1362
+ to: (0, import_viem5.getAddress)(token2.address),
1363
+ abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1197
1364
  functionName: "transferFrom",
1198
1365
  args: [fromAddress, receiver, BigInt(0)]
1199
1366
  }
@@ -1275,8 +1442,8 @@ var ActaAccount = class {
1275
1442
  const userOperation = yield accountClient.prepareUserOperation({
1276
1443
  calls: [
1277
1444
  {
1278
- to: (0, import_viem4.getAddress)(token2.address),
1279
- abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1445
+ to: (0, import_viem5.getAddress)(token2.address),
1446
+ abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1280
1447
  functionName: "transferFrom",
1281
1448
  args: [
1282
1449
  fromAddress,
@@ -1285,8 +1452,8 @@ var ActaAccount = class {
1285
1452
  ]
1286
1453
  },
1287
1454
  {
1288
- to: (0, import_viem4.getAddress)(token2.address),
1289
- abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1455
+ to: (0, import_viem5.getAddress)(token2.address),
1456
+ abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1290
1457
  functionName: "transferFrom",
1291
1458
  args: [fromAddress, receiver, receiverAmount]
1292
1459
  }
@@ -1386,7 +1553,7 @@ var ActaAccount = class {
1386
1553
  {
1387
1554
  target: token2.address,
1388
1555
  valueLimit: BigInt(0),
1389
- abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1556
+ abi: (0, import_viem5.parseAbi)(["function transferFrom(address,address,uint)"]),
1390
1557
  functionName: "transferFrom",
1391
1558
  args: [
1392
1559
  {
@@ -1433,119 +1600,6 @@ var ActaAccount = class {
1433
1600
  }
1434
1601
  };
1435
1602
 
1436
- // src/api.ts
1437
- var import_viem5 = require("viem");
1438
- var HttpMethod = /* @__PURE__ */ ((HttpMethod2) => {
1439
- HttpMethod2["Get"] = "get";
1440
- HttpMethod2["Post"] = "post";
1441
- HttpMethod2["Delete"] = "delete";
1442
- HttpMethod2["Update"] = "update";
1443
- return HttpMethod2;
1444
- })(HttpMethod || {});
1445
- function sendRequest(_0) {
1446
- return __async(this, arguments, function* ({
1447
- url,
1448
- method,
1449
- body,
1450
- headers = {}
1451
- }) {
1452
- var _a;
1453
- const response = yield fetch(url, {
1454
- method,
1455
- headers: __spreadProps(__spreadValues({}, headers), {
1456
- Accept: "application/json",
1457
- "Content-Type": "application/json"
1458
- }),
1459
- body: JSON.stringify(body)
1460
- });
1461
- let jsonResponse;
1462
- const res = yield response.json();
1463
- if (!response.ok) {
1464
- jsonResponse = {
1465
- error: {
1466
- code: response.status,
1467
- message: response.statusText
1468
- },
1469
- data: void 0
1470
- };
1471
- return jsonResponse;
1472
- }
1473
- if (!res) {
1474
- jsonResponse = {
1475
- error: {
1476
- code: 400,
1477
- message: "No response received."
1478
- },
1479
- data: void 0
1480
- };
1481
- return jsonResponse;
1482
- }
1483
- if (res == null ? void 0 : res.error) {
1484
- jsonResponse = {
1485
- error: {
1486
- code: response.status,
1487
- message: res.error
1488
- },
1489
- data: void 0
1490
- };
1491
- return jsonResponse;
1492
- }
1493
- jsonResponse = {
1494
- data: res.data,
1495
- message: (_a = res.message) != null ? _a : "Success",
1496
- error: void 0
1497
- };
1498
- return jsonResponse;
1499
- });
1500
- }
1501
- function createSessionAPICall(url, sessionBodyParams) {
1502
- return __async(this, null, function* () {
1503
- const response = yield sendRequest({
1504
- url,
1505
- method: "post" /* Post */,
1506
- body: sessionBodyParams
1507
- });
1508
- return response.data;
1509
- });
1510
- }
1511
- function verifySessionAPICall(url, sessionId) {
1512
- return __async(this, null, function* () {
1513
- const response = yield sendRequest({
1514
- url,
1515
- method: "get" /* Get */
1516
- });
1517
- return response.data;
1518
- });
1519
- }
1520
- function scheduleRecurringPaymentsAPICall(url, params) {
1521
- return __async(this, null, function* () {
1522
- const parsedParams = __spreadProps(__spreadValues({}, params), {
1523
- amount: (0, import_viem5.toHex)(params.amount)
1524
- });
1525
- const response = yield sendRequest({
1526
- url,
1527
- method: "post" /* Post */,
1528
- body: parsedParams
1529
- });
1530
- return response.data;
1531
- });
1532
- }
1533
- function executeSinglePaymentAPICall(url, userOperation, paymentParams, serviceParams) {
1534
- return __async(this, null, function* () {
1535
- const params = {
1536
- userOperation,
1537
- paymentParams,
1538
- serviceParams
1539
- };
1540
- const response = yield sendRequest({
1541
- url,
1542
- method: "post" /* Post */,
1543
- body: params
1544
- });
1545
- return response.data;
1546
- });
1547
- }
1548
-
1549
1603
  // src/deposit.ts
1550
1604
  var transactionServiceUrl = "https://api.acta.link/transaction/v1/";
1551
1605
  var depositServiceUrl = "https://api.acta.link/deposit/v1/";
@@ -1889,9 +1943,227 @@ var ActaDeposit = class {
1889
1943
  });
1890
1944
  }
1891
1945
  };
1946
+
1947
+ // src/billing.ts
1948
+ var import_viem7 = require("viem");
1949
+ var transactionServiceUrl2 = "http://localhost:8000/transaction/v1/";
1950
+ var ActaBilling = class {
1951
+ constructor(parameters) {
1952
+ this.count = 0;
1953
+ this.intervalUnit = void 0;
1954
+ this.startDate = void 0;
1955
+ this.endDate = void 0;
1956
+ this.serviceSessionParams = void 0;
1957
+ this.status = "not_started";
1958
+ this.serviceType = "deposit";
1959
+ this.allowMaxTokenApproval = false;
1960
+ var _a;
1961
+ this.connectorType = parameters.connectorType;
1962
+ this.walletClient = parameters.walletClient;
1963
+ this.signerAddress = parameters.signerAddress;
1964
+ this.chainId = parameters.chainId;
1965
+ this.token = parameters.token;
1966
+ this.amount = parameters.amount;
1967
+ this.receiver = parameters.receiver;
1968
+ this.feeInclusive = parameters.feeInclusive;
1969
+ this.paymentType = parameters.paymentType;
1970
+ this.count = parameters.count;
1971
+ this.intervalUnit = parameters.intervalUnit;
1972
+ this.startDate = parameters.startDate;
1973
+ this.endDate = parameters.endDate;
1974
+ this.allowMaxTokenApproval = (_a = parameters.allowMaxTokenApproval) != null ? _a : false;
1975
+ this.serviceType = parameters.serviceType;
1976
+ this.viemClient = new ViemClient(this.chainId, this.walletClient);
1977
+ this.account = new ActaAccount(
1978
+ this.chainId,
1979
+ this.viemClient.publicClient(),
1980
+ this.walletClient
1981
+ );
1982
+ }
1983
+ estimateSinglePaymentGas(parameters) {
1984
+ return __async(this, null, function* () {
1985
+ try {
1986
+ if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
1987
+ throw new Error("Only self custody payments are supported.");
1988
+ }
1989
+ const {
1990
+ estimatedGasCostInToken,
1991
+ ActalinkFeesInToken,
1992
+ feeInclusiveAmountInToken,
1993
+ feeExclusiveAmountInToken,
1994
+ estimatedTotalFeesInToken,
1995
+ paymaster,
1996
+ userOperation
1997
+ } = yield this.account.estimateSinglePaymentGas(parameters);
1998
+ return {
1999
+ estimatedGasCostInToken,
2000
+ ActalinkFeesInToken,
2001
+ feeInclusiveAmountInToken,
2002
+ feeExclusiveAmountInToken,
2003
+ estimatedTotalFeesInToken,
2004
+ paymaster,
2005
+ userOperation
2006
+ };
2007
+ } catch (error) {
2008
+ if (error instanceof Error) {
2009
+ throw new Error(error.message);
2010
+ }
2011
+ throw new Error("Failed to estimate single payment gas.");
2012
+ }
2013
+ });
2014
+ }
2015
+ createSinglePayment(servicePaymentParams) {
2016
+ return __async(this, null, function* () {
2017
+ try {
2018
+ if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
2019
+ throw new Error("Only self custody payments are supported.");
2020
+ }
2021
+ if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
2022
+ throw new Error("checkout session ID is required.");
2023
+ }
2024
+ const signerAddress = this.signerAddress;
2025
+ const chainId = this.chainId;
2026
+ const tokenSymbol = this.token;
2027
+ const amount = this.amount;
2028
+ const receiver = this.receiver;
2029
+ const feeInclusive = this.feeInclusive;
2030
+ const serviceType = this.serviceType;
2031
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2032
+ if (!token2) {
2033
+ throw new Error("Token not supported.");
2034
+ }
2035
+ const rpcParameters = yield this.account.signSinglePaymentOperation({
2036
+ signerAddress,
2037
+ chainId,
2038
+ token: tokenSymbol,
2039
+ amount,
2040
+ receiver,
2041
+ feeInclusive,
2042
+ allowMaxTokenApproval: this.allowMaxTokenApproval
2043
+ });
2044
+ const txn = yield executeSinglePaymentAPICall(
2045
+ `${transactionServiceUrl2}execute/single`,
2046
+ rpcParameters,
2047
+ {
2048
+ senderAddress: signerAddress,
2049
+ receiverAddress: receiver,
2050
+ chainId,
2051
+ tokenAddress: token2.address,
2052
+ amount: (0, import_viem7.toHex)(amount),
2053
+ feeInclusive,
2054
+ serviceType
2055
+ },
2056
+ servicePaymentParams
2057
+ );
2058
+ return txn.transaction.id;
2059
+ } catch (error) {
2060
+ if (error instanceof Error) {
2061
+ throw new Error(error.message);
2062
+ }
2063
+ throw new Error("Failed to create payment.");
2064
+ }
2065
+ });
2066
+ }
2067
+ createRecurringPayments(servicePaymentParams) {
2068
+ return __async(this, null, function* () {
2069
+ if (this.connectorType !== "Self-Custody" /* SELF_CUSTODY */) {
2070
+ throw new Error("Only self custody payments are supported.");
2071
+ }
2072
+ if (!servicePaymentParams.checkoutSessionId || servicePaymentParams.checkoutSessionId === "") {
2073
+ throw new Error("checkout session ID is required.");
2074
+ }
2075
+ if (!this.walletClient) {
2076
+ throw new Error("Signer is required for self custody payments.");
2077
+ }
2078
+ const signerAddress = this.signerAddress;
2079
+ const chainId = this.chainId;
2080
+ const tokenSymbol = this.token;
2081
+ const amount = this.amount;
2082
+ const receiver = this.receiver;
2083
+ const feeInclusive = this.feeInclusive;
2084
+ const count = this.count;
2085
+ const intervalUnit = this.intervalUnit;
2086
+ const startDate = this.startDate;
2087
+ const endDate = this.endDate;
2088
+ const serviceType = this.serviceType;
2089
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2090
+ if (!token2) {
2091
+ throw new Error("Token not supported.");
2092
+ }
2093
+ if (!chainId || !count || !intervalUnit || !startDate || !endDate) {
2094
+ throw new Error("Invalid parameters.");
2095
+ }
2096
+ const approval = yield this.account.signRecurringPayments({
2097
+ signerAddress,
2098
+ chainId,
2099
+ token: tokenSymbol,
2100
+ amount,
2101
+ feeInclusive,
2102
+ count,
2103
+ intervalUnit,
2104
+ startDate,
2105
+ endDate,
2106
+ receiver,
2107
+ allowMaxTokenApproval: this.allowMaxTokenApproval
2108
+ });
2109
+ const txn = yield scheduleRecurringPaymentsAPICall(
2110
+ `${transactionServiceUrl2}schedule/recurring`,
2111
+ {
2112
+ amount,
2113
+ chainId,
2114
+ feeInclusive,
2115
+ intervalCount: count,
2116
+ intervalUnit,
2117
+ senderAddress: signerAddress,
2118
+ receiverAddress: receiver,
2119
+ tokenAddress: token2.address,
2120
+ startAt: startDate,
2121
+ endAt: endDate,
2122
+ approval,
2123
+ serviceParams: servicePaymentParams,
2124
+ serviceType
2125
+ }
2126
+ );
2127
+ return txn.recurringTransaction.id;
2128
+ });
2129
+ }
2130
+ getPaymentSteps() {
2131
+ return __async(this, null, function* () {
2132
+ const signerAddress = this.signerAddress;
2133
+ const chainId = this.chainId;
2134
+ const tokenSymbol = this.token;
2135
+ const amount = this.amount;
2136
+ const receiver = this.receiver;
2137
+ const feeInclusive = this.feeInclusive;
2138
+ const count = this.count;
2139
+ if (!signerAddress) return ["allowance", "confirm"];
2140
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2141
+ if (!token2) return ["allowance", "confirm"];
2142
+ const smartAccount = yield this.account.createAccount();
2143
+ const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
2144
+ chainId,
2145
+ amount,
2146
+ feeInclusive,
2147
+ receiver,
2148
+ signerAddress,
2149
+ token: tokenSymbol
2150
+ });
2151
+ const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
2152
+ let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
2153
+ const allowance = yield this.viemClient.checkTokenAllowance(
2154
+ token2,
2155
+ signerAddress,
2156
+ smartAccount.address
2157
+ );
2158
+ if (paymentAmount <= allowance) return ["confirm"];
2159
+ return ["allowance", "confirm"];
2160
+ });
2161
+ }
2162
+ };
1892
2163
  // Annotate the CommonJS export names for ESM import in node:
1893
2164
  0 && (module.exports = {
1894
2165
  ActaAccount,
2166
+ ActaBilling,
1895
2167
  ActaDeposit,
1896
2168
  ConnectorType,
1897
2169
  HttpMethod,
@@ -1917,6 +2189,8 @@ var ActaDeposit = class {
1917
2189
  bscUSDT,
1918
2190
  bscWBNB,
1919
2191
  bytesToBase64,
2192
+ createBillingCheckoutSession,
2193
+ createBillingSessionAPICall,
1920
2194
  createPolicyFromParams,
1921
2195
  createSessionAPICall,
1922
2196
  decodeParamsFromInitCode,
@@ -1929,6 +2203,8 @@ var ActaDeposit = class {
1929
2203
  ethereumUSDT,
1930
2204
  ethereumWETH,
1931
2205
  executeSinglePaymentAPICall,
2206
+ fetchBillingSessionDetails,
2207
+ getBillingPaymentSessionDetails,
1932
2208
  getChainById,
1933
2209
  getChainExplorerByChainId,
1934
2210
  getPeriodInterval,