@actalink/commonlib 0.0.14 → 0.0.16

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
@@ -102,6 +102,7 @@ __export(index_exports, {
102
102
  ethereumUSDC: () => ethereumUSDC,
103
103
  ethereumUSDT: () => ethereumUSDT,
104
104
  ethereumWETH: () => ethereumWETH,
105
+ executeScheduleBatchPaymentAPICall: () => executeScheduleBatchPaymentAPICall,
105
106
  executeSingleBatchPaymentAPICall: () => executeSingleBatchPaymentAPICall,
106
107
  executeSinglePaymentAPICall: () => executeSinglePaymentAPICall,
107
108
  fetchBatchInstructionDetails: () => fetchBatchInstructionDetails,
@@ -121,6 +122,7 @@ __export(index_exports, {
121
122
  lineaETH: () => lineaETH,
122
123
  lineaUSDC: () => lineaUSDC,
123
124
  lineaWETH: () => lineaWETH,
125
+ mainnetChains: () => mainnetChains,
124
126
  optimismDAI: () => optimismDAI,
125
127
  optimismETH: () => optimismETH,
126
128
  optimismUSDC: () => optimismUSDC,
@@ -141,6 +143,7 @@ __export(index_exports, {
141
143
  serializePermissionAccountParams: () => serializePermissionAccountParams,
142
144
  supportedChains: () => supportedChains,
143
145
  supportedTokensByChain: () => supportedTokensByChain,
146
+ testnetChains: () => testnetChains,
144
147
  toECDSASigner: () => toECDSASigner2,
145
148
  toPermissionValidator: () => toPermissionValidator2,
146
149
  toPolicyId: () => toPolicyId,
@@ -169,6 +172,8 @@ var supportedChains = [
169
172
  import_chains.sepolia,
170
173
  import_chains.polygonAmoy
171
174
  ];
175
+ var mainnetChains = [import_chains2.arbitrum, import_chains2.base, import_chains2.bsc, import_chains2.mainnet, import_chains2.optimism, import_chains2.polygon];
176
+ var testnetChains = [import_chains.sepolia, import_chains.baseSepolia, import_chains.polygonAmoy];
172
177
  function getChainById(chainId) {
173
178
  const chain = supportedChains.find((c) => c.id === chainId);
174
179
  if (!chain) throw new Error(`Chain ${chainId} not supported.`);
@@ -537,7 +542,7 @@ var polygonUSDCe = token({
537
542
  });
538
543
  var polygonTokens = [polygonUSDC, polygonUSDT];
539
544
  var polygonAmoyUSDC = token({
540
- chainId: import_chains3.polygon.id,
545
+ chainId: import_chains3.polygonAmoy.id,
541
546
  address: (0, import_viem.getAddress)("0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582"),
542
547
  decimals: 6,
543
548
  fiatISO: "USDC",
@@ -547,7 +552,7 @@ var polygonAmoyUSDC = token({
547
552
  });
548
553
  var polygonAmoyTokens = [polygonAmoyUSDC];
549
554
  var baseSepoliaUSDC = token({
550
- chainId: import_chains3.polygon.id,
555
+ chainId: import_chains3.baseSepolia.id,
551
556
  address: (0, import_viem.getAddress)("0x036CbD53842c5426634e7929541eC2318f3dCF7e"),
552
557
  decimals: 6,
553
558
  fiatISO: "USDC",
@@ -557,7 +562,7 @@ var baseSepoliaUSDC = token({
557
562
  });
558
563
  var baseSepoliaTokens = [baseSepoliaUSDC];
559
564
  var sepoliaUSDC = token({
560
- chainId: import_chains3.polygon.id,
565
+ chainId: import_chains3.sepolia.id,
561
566
  address: (0, import_viem.getAddress)("0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"),
562
567
  decimals: 6,
563
568
  fiatISO: "USDC",
@@ -787,7 +792,7 @@ var ViemClient = class {
787
792
  });
788
793
  const receipt = yield this.publicClient().waitForTransactionReceipt({
789
794
  hash: txn,
790
- confirmations: token2.chainId === 1 ? 1 : 5
795
+ confirmations: token2.chainId === 1 || 11155111 ? 1 : 5
791
796
  });
792
797
  return amount;
793
798
  }
@@ -874,7 +879,8 @@ var ActaAccount = class {
874
879
  chainId,
875
880
  token: tokenSymbol,
876
881
  amount,
877
- receiver
882
+ receiver,
883
+ feebps
878
884
  } = parameters;
879
885
  if (amount <= BigInt(0)) {
880
886
  throw new Error("Amount must be greater than 0.");
@@ -890,11 +896,6 @@ var ActaAccount = class {
890
896
  if (!token2) {
891
897
  throw new Error("Token not found.");
892
898
  }
893
- const quotes = yield pimlicoClient.getTokenQuotes({
894
- tokens: [token2.address],
895
- chain: getChainById(chainId)
896
- });
897
- const { postOpGas, exchangeRate, paymaster } = quotes[0];
898
899
  const userOperation = yield accountClient.prepareUserOperation({
899
900
  calls: [
900
901
  {
@@ -915,22 +916,31 @@ var ActaAccount = class {
915
916
  }
916
917
  ]
917
918
  });
918
- const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
919
- const userOperationMaxCost = BigInt(
920
- userOperationMaxGas * userOperation.maxFeePerGas
921
- );
922
- const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
923
- const ActalinkFeesInToken = amount * BigInt(20) / BigInt(1e4);
924
- const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
919
+ const quotes = yield pimlicoClient.getTokenQuotes({
920
+ tokens: [token2.address],
921
+ chain: getChainById(chainId)
922
+ });
923
+ const userOperationMaxCost = (0, import_permissionless.getRequiredPrefund)({
924
+ userOperation,
925
+ entryPointVersion: "0.7"
926
+ });
927
+ const postOpGas = quotes[0].postOpGas;
928
+ const exchangeRate = quotes[0].exchangeRate;
929
+ const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd;
930
+ const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
931
+ const costInToken = maxCostInWei * exchangeRate / BigInt(1e18);
932
+ const costInUsd = maxCostInWei * exchangeRateNativeToUsd / BigInt(1e18);
933
+ const ActalinkFeesInToken = amount * BigInt(feebps) / BigInt(1e4);
934
+ const estimatedTotalFeesInToken = costInToken + ActalinkFeesInToken;
925
935
  const feeInclusiveAmountInToken = amount - estimatedTotalFeesInToken;
926
936
  const feeExclusiveAmountInToken = amount + estimatedTotalFeesInToken;
927
937
  return {
928
- estimatedGasCostInToken,
938
+ estimatedGasCostInToken: costInToken,
929
939
  ActalinkFeesInToken,
930
940
  estimatedTotalFeesInToken,
931
941
  feeInclusiveAmountInToken,
932
942
  feeExclusiveAmountInToken,
933
- paymaster,
943
+ paymaster: quotes[0].paymaster,
934
944
  userOperation
935
945
  };
936
946
  });
@@ -944,7 +954,8 @@ var ActaAccount = class {
944
954
  receivers,
945
955
  feeInclusive,
946
956
  walletClient,
947
- totalAmount
957
+ totalAmount,
958
+ feebps
948
959
  } = parameters;
949
960
  if (totalAmount <= BigInt(0)) {
950
961
  throw new Error("Amount must be greater than 0.");
@@ -960,14 +971,6 @@ var ActaAccount = class {
960
971
  if (!token2) {
961
972
  throw new Error("Token not found.");
962
973
  }
963
- console.log(`fromAddress: ${fromAddress}`);
964
- const quotes = yield pimlicoClient.getTokenQuotes({
965
- tokens: [token2.address],
966
- chain: getChainById(chainId)
967
- });
968
- const { postOpGas, exchangeRate, paymaster } = quotes[0];
969
- console.log("preparing");
970
- console.log(token2.address);
971
974
  const receiversData = receivers.map((r) => {
972
975
  return {
973
976
  to: (0, import_viem3.getAddress)(token2.address),
@@ -992,17 +995,27 @@ var ActaAccount = class {
992
995
  }
993
996
  ]
994
997
  });
995
- const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
996
- const userOperationMaxCost = BigInt(
997
- userOperationMaxGas * userOperation.maxFeePerGas
998
- );
999
- const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
1000
- const ActalinkFeesInToken = totalAmount * BigInt(20) / BigInt(1e4);
1001
- const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
998
+ const quotes = yield pimlicoClient.getTokenQuotes({
999
+ tokens: [token2.address],
1000
+ chain: getChainById(chainId)
1001
+ });
1002
+ const userOperationMaxCost = (0, import_permissionless.getRequiredPrefund)({
1003
+ userOperation,
1004
+ entryPointVersion: "0.7"
1005
+ });
1006
+ const postOpGas = quotes[0].postOpGas;
1007
+ const exchangeRate = quotes[0].exchangeRate;
1008
+ const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd;
1009
+ const paymaster = quotes[0].paymaster;
1010
+ const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
1011
+ const costInToken = maxCostInWei * exchangeRate / BigInt(1e18);
1012
+ const costInUsd = maxCostInWei * exchangeRateNativeToUsd / BigInt(1e18);
1013
+ const ActalinkFeesInToken = totalAmount * BigInt(feebps) / BigInt(1e4);
1014
+ const estimatedTotalFeesInToken = costInToken + ActalinkFeesInToken;
1002
1015
  const feeInclusiveAmountInToken = totalAmount - estimatedTotalFeesInToken;
1003
1016
  const feeExclusiveAmountInToken = totalAmount + estimatedTotalFeesInToken;
1004
1017
  return {
1005
- estimatedGasCostInToken,
1018
+ estimatedGasCostInToken: costInToken,
1006
1019
  ActalinkFeesInToken,
1007
1020
  estimatedTotalFeesInToken,
1008
1021
  feeInclusiveAmountInToken,
@@ -1025,7 +1038,8 @@ var ActaAccount = class {
1025
1038
  amount,
1026
1039
  receiver,
1027
1040
  feeInclusive,
1028
- allowMaxTokenApproval
1041
+ allowMaxTokenApproval,
1042
+ feebps
1029
1043
  } = singlePaymentParams;
1030
1044
  if (amount <= BigInt(0)) {
1031
1045
  throw new Error("Amount must be greater than 0.");
@@ -1051,7 +1065,8 @@ var ActaAccount = class {
1051
1065
  token: tokenSymbol,
1052
1066
  amount,
1053
1067
  receiver,
1054
- feeInclusive
1068
+ feeInclusive,
1069
+ feebps
1055
1070
  });
1056
1071
  const account = yield this.createAccount();
1057
1072
  const { accountClient } = yield this.createAccountHelpers();
@@ -1074,7 +1089,7 @@ var ActaAccount = class {
1074
1089
  args: [
1075
1090
  fromAddress,
1076
1091
  "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1077
- estimatedGasCostInToken
1092
+ estimatedTotalFeesInToken
1078
1093
  ]
1079
1094
  },
1080
1095
  {
@@ -1114,7 +1129,8 @@ var ActaAccount = class {
1114
1129
  feeInclusive,
1115
1130
  allowMaxTokenApproval,
1116
1131
  totalAmount,
1117
- walletClient
1132
+ walletClient,
1133
+ feebps
1118
1134
  } = singlePaymentParams;
1119
1135
  if (totalAmount <= BigInt(0)) {
1120
1136
  throw new Error("Amount must be greater than 0.");
@@ -1128,7 +1144,6 @@ var ActaAccount = class {
1128
1144
  }
1129
1145
  const viemClient = new ViemClient(this.chainId, this.signer);
1130
1146
  console.log("validating gas");
1131
- console.log(receivers);
1132
1147
  const {
1133
1148
  estimatedGasCostInToken,
1134
1149
  ActalinkFeesInToken,
@@ -1143,7 +1158,8 @@ var ActaAccount = class {
1143
1158
  receivers,
1144
1159
  feeInclusive,
1145
1160
  totalAmount,
1146
- walletClient
1161
+ walletClient,
1162
+ feebps
1147
1163
  });
1148
1164
  const account = yield this.createAccount();
1149
1165
  const { accountClient } = yield this.createAccountHelpers();
@@ -1212,7 +1228,8 @@ var ActaAccount = class {
1212
1228
  intervalUnit,
1213
1229
  startDate,
1214
1230
  endDate,
1215
- allowMaxTokenApproval
1231
+ allowMaxTokenApproval,
1232
+ feebps
1216
1233
  } = recurringPaymentParams;
1217
1234
  if (amount <= BigInt(0)) {
1218
1235
  throw new Error("Amount must be greater than 0.");
@@ -1262,7 +1279,8 @@ var ActaAccount = class {
1262
1279
  token: tokenSymbol,
1263
1280
  amount,
1264
1281
  receiver,
1265
- feeInclusive
1282
+ feeInclusive,
1283
+ feebps
1266
1284
  });
1267
1285
  const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1268
1286
  const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
@@ -1327,6 +1345,135 @@ var ActaAccount = class {
1327
1345
  return { approval, amountExclusive };
1328
1346
  });
1329
1347
  }
1348
+ signRecurringOrScheduleBatchPayments(paymentParams) {
1349
+ return __async(this, null, function* () {
1350
+ if (!this.signer) {
1351
+ throw new Error("Signer is required for self custody payments.");
1352
+ }
1353
+ const {
1354
+ signerAddress,
1355
+ chainId,
1356
+ token: tokenSymbol,
1357
+ feeInclusive,
1358
+ count,
1359
+ allowMaxTokenApproval,
1360
+ receivers,
1361
+ totalAmount,
1362
+ walletClient,
1363
+ feebps
1364
+ } = paymentParams;
1365
+ if (signerAddress === void 0) {
1366
+ throw new Error("signer address is not provided.");
1367
+ }
1368
+ if (totalAmount <= BigInt(0)) {
1369
+ throw new Error("Amount must be greater than 0.");
1370
+ }
1371
+ if (receivers.length === 0) {
1372
+ throw new Error("Receivers not found for batch payment");
1373
+ }
1374
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1375
+ if (!token2) {
1376
+ throw new Error("Token not found.");
1377
+ }
1378
+ const kernelVersion = import_constants.KERNEL_V3_1;
1379
+ const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1380
+ const paymentCount = count != null ? count : 24;
1381
+ const account = yield this.createAccount();
1382
+ const smartAccountAddress = account.address;
1383
+ const viemClient = new ViemClient(this.chainId, this.signer);
1384
+ const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1385
+ const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(
1386
+ viemClient.publicClient(),
1387
+ {
1388
+ entryPoint,
1389
+ kernelVersion,
1390
+ signer: this.signer
1391
+ }
1392
+ );
1393
+ const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1394
+ const emptyAccount = (0, import_sdk.addressToEmptyAccount)(sessionKeyAddress);
1395
+ const emptySessionKeySigner = yield (0, import_signers.toECDSASigner)({ signer: emptyAccount });
1396
+ const {
1397
+ estimatedGasCostInToken,
1398
+ ActalinkFeesInToken,
1399
+ feeInclusiveAmountInToken,
1400
+ feeExclusiveAmountInToken,
1401
+ estimatedTotalFeesInToken,
1402
+ paymaster
1403
+ } = yield this.estimateSingleBatchPaymentGas({
1404
+ signerAddress,
1405
+ chainId,
1406
+ token: tokenSymbol,
1407
+ receivers,
1408
+ feeInclusive,
1409
+ totalAmount,
1410
+ walletClient,
1411
+ feebps
1412
+ });
1413
+ const amountToTransfer = feeInclusive ? totalAmount : feeExclusiveAmountInToken;
1414
+ const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : totalAmount;
1415
+ yield viemClient.checkAndApproveToken(
1416
+ token2,
1417
+ smartAccountAddress,
1418
+ amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
1419
+ allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1420
+ );
1421
+ const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
1422
+ const receiversAddress = receivers.map((r) => (0, import_viem3.getAddress)(r.address));
1423
+ const callPolicy = (0, import_policies.toCallPolicy)({
1424
+ policyVersion: import_policies.CallPolicyVersion.V0_0_4,
1425
+ permissions: [
1426
+ {
1427
+ target: token2.address,
1428
+ valueLimit: BigInt(0),
1429
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
1430
+ functionName: "transferFrom",
1431
+ args: [
1432
+ {
1433
+ condition: import_policies.ParamCondition.EQUAL,
1434
+ value: (0, import_viem3.getAddress)(signerAddress)
1435
+ },
1436
+ {
1437
+ condition: import_policies.ParamCondition.ONE_OF,
1438
+ value: [
1439
+ "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1440
+ ...receiversAddress
1441
+ ]
1442
+ },
1443
+ {
1444
+ condition: import_policies.ParamCondition.LESS_THAN_OR_EQUAL,
1445
+ value: amountExclusive
1446
+ }
1447
+ ]
1448
+ }
1449
+ ]
1450
+ });
1451
+ const permissionPlugin = yield (0, import_permissions.toPermissionValidator)(
1452
+ viemClient.publicClient(),
1453
+ {
1454
+ entryPoint,
1455
+ kernelVersion,
1456
+ signer: emptySessionKeySigner,
1457
+ policies: [callPolicy]
1458
+ }
1459
+ );
1460
+ const serializedSessionKeyAccount = yield (0, import_sdk.createKernelAccount)(
1461
+ viemClient.publicClient(),
1462
+ {
1463
+ entryPoint,
1464
+ kernelVersion,
1465
+ plugins: {
1466
+ sudo: ecdsaValidator,
1467
+ regular: permissionPlugin
1468
+ }
1469
+ }
1470
+ );
1471
+ const approval = yield (0, import_permissions.serializePermissionAccount)(
1472
+ serializedSessionKeyAccount
1473
+ );
1474
+ return { approval, amountExclusive };
1475
+ });
1476
+ }
1330
1477
  signRecurringTransactionCancellation(paymentCancellationParams) {
1331
1478
  return __async(this, null, function* () {
1332
1479
  var _a;
@@ -1574,6 +1721,23 @@ function executeSingleBatchPaymentAPICall(url, APIKey, userOperation, paymentPar
1574
1721
  return response.data;
1575
1722
  });
1576
1723
  }
1724
+ function executeScheduleBatchPaymentAPICall(url, APIKey, paymentParams, serviceParams) {
1725
+ return __async(this, null, function* () {
1726
+ const params = {
1727
+ paymentParams,
1728
+ serviceParams
1729
+ };
1730
+ const response = yield sendRequest({
1731
+ url,
1732
+ method: "post" /* Post */,
1733
+ body: params,
1734
+ headers: {
1735
+ "x-api-key": APIKey
1736
+ }
1737
+ });
1738
+ return response.data;
1739
+ });
1740
+ }
1577
1741
  function fetchRecurringTransactionWithId(url) {
1578
1742
  return __async(this, null, function* () {
1579
1743
  const response = yield sendRequest({ url, method: "get" /* Get */ });
@@ -1626,6 +1790,7 @@ var transactionServiceUrl = "https://api.acta.link/transaction/v1/";
1626
1790
  var depositServiceUrl = "https://api.acta.link/deposit/v1/";
1627
1791
  var ActaDeposit = class {
1628
1792
  constructor(parameters) {
1793
+ this.feeInclusive = false;
1629
1794
  this.count = 0;
1630
1795
  this.intervalUnit = void 0;
1631
1796
  this.startDate = void 0;
@@ -1635,7 +1800,7 @@ var ActaDeposit = class {
1635
1800
  this.status = "not_started";
1636
1801
  this.serviceType = "deposit";
1637
1802
  this.allowMaxTokenApproval = false;
1638
- var _a, _b;
1803
+ var _a, _b, _c;
1639
1804
  this.connectorType = parameters.connectorType;
1640
1805
  this.walletClient = parameters.walletClient;
1641
1806
  this.signerAddress = parameters.signerAddress;
@@ -1643,14 +1808,14 @@ var ActaDeposit = class {
1643
1808
  this.token = parameters.token;
1644
1809
  this.amount = parameters.amount;
1645
1810
  this.receiver = parameters.receiver;
1646
- this.feeInclusive = parameters.feeInclusive;
1811
+ this.feeInclusive = (_a = parameters.feeInclusive) != null ? _a : false;
1647
1812
  this.paymentType = parameters.paymentType;
1648
1813
  this.count = parameters.count;
1649
1814
  this.intervalUnit = parameters.intervalUnit;
1650
1815
  this.startDate = parameters.startDate;
1651
1816
  this.endDate = parameters.endDate;
1652
- this.depositSessionId = (_a = parameters.depositSessionId) != null ? _a : "";
1653
- this.allowMaxTokenApproval = (_b = parameters.allowMaxTokenApproval) != null ? _b : false;
1817
+ this.depositSessionId = (_b = parameters.depositSessionId) != null ? _b : "";
1818
+ this.allowMaxTokenApproval = (_c = parameters.allowMaxTokenApproval) != null ? _c : false;
1654
1819
  this.viemClient = new ViemClient(this.chainId, this.walletClient);
1655
1820
  this.account = new ActaAccount(
1656
1821
  this.chainId,
@@ -1815,7 +1980,8 @@ var ActaDeposit = class {
1815
1980
  amount,
1816
1981
  receiver,
1817
1982
  feeInclusive,
1818
- allowMaxTokenApproval: this.allowMaxTokenApproval
1983
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
1984
+ feebps: 10
1819
1985
  });
1820
1986
  const txn = yield executeSinglePaymentAPICall(
1821
1987
  `${transactionServiceUrl}execute/single`,
@@ -1908,7 +2074,8 @@ var ActaDeposit = class {
1908
2074
  startDate,
1909
2075
  endDate,
1910
2076
  receiver,
1911
- allowMaxTokenApproval: this.allowMaxTokenApproval
2077
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
2078
+ feebps: 20
1912
2079
  });
1913
2080
  const txn = yield scheduleRecurringPaymentsAPICall(
1914
2081
  `${transactionServiceUrl}schedule/recurring`,
@@ -1951,7 +2118,8 @@ var ActaDeposit = class {
1951
2118
  feeInclusive,
1952
2119
  receiver,
1953
2120
  signerAddress,
1954
- token: tokenSymbol
2121
+ token: tokenSymbol,
2122
+ feebps: 10
1955
2123
  });
1956
2124
  const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1957
2125
  let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
@@ -1971,6 +2139,7 @@ var import_viem6 = require("viem");
1971
2139
  var transactionServiceUrl2 = "https://api.acta.link/transaction/v1/";
1972
2140
  var ActaBilling = class {
1973
2141
  constructor(parameters) {
2142
+ this.feeInclusive = true;
1974
2143
  this.count = 0;
1975
2144
  this.intervalUnit = void 0;
1976
2145
  this.startDate = void 0;
@@ -1979,7 +2148,7 @@ var ActaBilling = class {
1979
2148
  this.status = "not_started";
1980
2149
  this.serviceType = "deposit";
1981
2150
  this.allowMaxTokenApproval = false;
1982
- var _a;
2151
+ var _a, _b;
1983
2152
  this.connectorType = parameters.connectorType;
1984
2153
  this.walletClient = parameters.walletClient;
1985
2154
  this.signerAddress = parameters.signerAddress;
@@ -1987,13 +2156,13 @@ var ActaBilling = class {
1987
2156
  this.token = parameters.token;
1988
2157
  this.amount = parameters.amount;
1989
2158
  this.receiver = parameters.receiver;
1990
- this.feeInclusive = parameters.feeInclusive;
2159
+ this.feeInclusive = (_a = parameters.feeInclusive) != null ? _a : true;
1991
2160
  this.paymentType = parameters.paymentType;
1992
2161
  this.count = parameters.count;
1993
2162
  this.intervalUnit = parameters.intervalUnit;
1994
2163
  this.startDate = parameters.startDate;
1995
2164
  this.endDate = parameters.endDate;
1996
- this.allowMaxTokenApproval = (_a = parameters.allowMaxTokenApproval) != null ? _a : false;
2165
+ this.allowMaxTokenApproval = (_b = parameters.allowMaxTokenApproval) != null ? _b : false;
1997
2166
  this.serviceType = parameters.serviceType;
1998
2167
  this.viemClient = new ViemClient(this.chainId, this.walletClient);
1999
2168
  this.account = new ActaAccount(
@@ -2061,7 +2230,8 @@ var ActaBilling = class {
2061
2230
  amount,
2062
2231
  receiver,
2063
2232
  feeInclusive,
2064
- allowMaxTokenApproval: this.allowMaxTokenApproval
2233
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
2234
+ feebps: 20
2065
2235
  });
2066
2236
  const txn = yield executeSinglePaymentAPICall(
2067
2237
  `${transactionServiceUrl2}execute/single`,
@@ -2126,7 +2296,8 @@ var ActaBilling = class {
2126
2296
  startDate,
2127
2297
  endDate,
2128
2298
  receiver,
2129
- allowMaxTokenApproval: this.allowMaxTokenApproval
2299
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
2300
+ feebps: 20
2130
2301
  });
2131
2302
  const txn = yield scheduleRecurringPaymentsAPICall(
2132
2303
  `${transactionServiceUrl2}schedule/recurring`,
@@ -2169,7 +2340,8 @@ var ActaBilling = class {
2169
2340
  feeInclusive,
2170
2341
  receiver,
2171
2342
  signerAddress,
2172
- token: tokenSymbol
2343
+ token: tokenSymbol,
2344
+ feebps: 20
2173
2345
  });
2174
2346
  const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
2175
2347
  let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
@@ -2186,7 +2358,28 @@ var ActaBilling = class {
2186
2358
 
2187
2359
  // src/batch.ts
2188
2360
  var import_viem7 = require("viem");
2361
+ var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2189
2362
  var batchServiceUrl = "https://api.acta.link/batch/api/v1/";
2363
+ var transactionServiceTestUrl = "https://api.acta.link/transaction/test/v1/";
2364
+ var batchServiceTestUrl = "https://api.acta.link/batch/test/api/v1/";
2365
+ var returnEnvUrl = (chainId) => {
2366
+ const mainnetChain = mainnetChains.find((c) => c.id === chainId);
2367
+ const testnetChain = testnetChains.find((c) => c.id === chainId);
2368
+ if (!mainnetChain && !testnetChain) {
2369
+ throw new Error(`Chain ${chainId} not supported.`);
2370
+ }
2371
+ if (mainnetChain) {
2372
+ return {
2373
+ envTransactionServiceUrl: transactionServiceUrl3,
2374
+ envBatchServiceUrl: batchServiceUrl
2375
+ };
2376
+ } else {
2377
+ return {
2378
+ envTransactionServiceUrl: transactionServiceTestUrl,
2379
+ envBatchServiceUrl: batchServiceTestUrl
2380
+ };
2381
+ }
2382
+ };
2190
2383
  var ActaBatch = class {
2191
2384
  constructor(parameters) {
2192
2385
  this.APIkey = parameters.APIKey;
@@ -2207,8 +2400,9 @@ var ActaBatch = class {
2207
2400
  if (!instructionId || instructionId === "") {
2208
2401
  throw new Error("Instruction id is required");
2209
2402
  }
2403
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2210
2404
  const session = yield createBatchSessionAPICall(
2211
- `${batchServiceUrl}create/session`,
2405
+ `${envBatchServiceUrl}create/session`,
2212
2406
  this.APIkey,
2213
2407
  {
2214
2408
  name,
@@ -2240,8 +2434,13 @@ var ActaBatch = class {
2240
2434
  walletClient,
2241
2435
  instructionId
2242
2436
  } = parameters;
2437
+ let isFeeInclusive = false;
2438
+ if (feeInclusive) {
2439
+ isFeeInclusive = true;
2440
+ }
2441
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2243
2442
  const instuctionData = yield fetchBatchInstructionDetails(
2244
- `${batchServiceUrl}instruction/${instructionId}`,
2443
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2245
2444
  this.APIkey
2246
2445
  );
2247
2446
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2281,12 +2480,13 @@ var ActaBatch = class {
2281
2480
  userOperation
2282
2481
  } = yield account.estimateSingleBatchPaymentGas({
2283
2482
  chainId,
2284
- feeInclusive,
2483
+ feeInclusive: isFeeInclusive,
2285
2484
  signerAddress,
2286
2485
  token: token2,
2287
2486
  walletClient,
2288
2487
  receivers,
2289
- totalAmount: totalAmountParsed
2488
+ totalAmount: totalAmountParsed,
2489
+ feebps: 20
2290
2490
  });
2291
2491
  return {
2292
2492
  estimatedGasCostInToken,
@@ -2317,8 +2517,13 @@ var ActaBatch = class {
2317
2517
  allowMaxTokenApproval,
2318
2518
  instructionId
2319
2519
  } = params;
2520
+ let isFeeInclusive = false;
2521
+ if (feeInclusive) {
2522
+ isFeeInclusive = true;
2523
+ }
2524
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2320
2525
  const instuctionData = yield fetchBatchInstructionDetails(
2321
- `${batchServiceUrl}instruction/${instructionId}`,
2526
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2322
2527
  this.APIkey
2323
2528
  );
2324
2529
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2354,14 +2559,15 @@ var ActaBatch = class {
2354
2559
  signerAddress,
2355
2560
  chainId,
2356
2561
  token: tokenSymbol,
2357
- feeInclusive,
2562
+ feeInclusive: isFeeInclusive,
2358
2563
  receivers,
2359
2564
  totalAmount: totalAmountParsed,
2360
2565
  walletClient,
2361
- allowMaxTokenApproval
2566
+ allowMaxTokenApproval,
2567
+ feebps: 20
2362
2568
  });
2363
2569
  const txn = yield executeSingleBatchPaymentAPICall(
2364
- `${batchServiceUrl}execute/single/batch`,
2570
+ `${envBatchServiceUrl}execute/single/batch`,
2365
2571
  this.APIkey,
2366
2572
  rpcParameters,
2367
2573
  {
@@ -2369,7 +2575,7 @@ var ActaBatch = class {
2369
2575
  chainId,
2370
2576
  tokenAddress: tokenData.address,
2371
2577
  amount: (0, import_viem7.toHex)(totalAmountParsed),
2372
- feeInclusive,
2578
+ feeInclusive: isFeeInclusive,
2373
2579
  serviceType: "batch"
2374
2580
  },
2375
2581
  serviceParams
@@ -2384,6 +2590,103 @@ var ActaBatch = class {
2384
2590
  }
2385
2591
  });
2386
2592
  }
2593
+ createScheduleBatchPayment(params, serviceParams) {
2594
+ return __async(this, null, function* () {
2595
+ try {
2596
+ const {
2597
+ chainId,
2598
+ feeInclusive,
2599
+ signerAddress,
2600
+ token: tokenSymbol,
2601
+ walletClient,
2602
+ allowMaxTokenApproval,
2603
+ instructionId,
2604
+ executionTime
2605
+ } = params;
2606
+ let isFeeInclusive = false;
2607
+ if (feeInclusive) {
2608
+ isFeeInclusive = true;
2609
+ }
2610
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2611
+ if (executionTime <= Date.now() + 1e3 * 60 * 2) {
2612
+ throw new Error(
2613
+ "Execution time must be more than 5 mins from current time."
2614
+ );
2615
+ }
2616
+ const instuctionData = yield fetchBatchInstructionDetails(
2617
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2618
+ this.APIkey
2619
+ );
2620
+ if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
2621
+ throw new Error("Instruction not found");
2622
+ }
2623
+ console.log(instuctionData);
2624
+ const tokenData = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2625
+ if (!tokenData) {
2626
+ throw new Error("Token not supported");
2627
+ }
2628
+ const totalAmount = instuctionData.totalAmount;
2629
+ const totalAmountParsed = BigInt(
2630
+ (0, import_viem7.parseUnits)(totalAmount, tokenData.decimals)
2631
+ );
2632
+ const receivers = instuctionData.receivers.map(
2633
+ (i) => {
2634
+ const receiver = (0, import_viem7.getAddress)(i.address);
2635
+ const tokenAmount = BigInt((0, import_viem7.parseUnits)(i.amount, tokenData.decimals));
2636
+ return {
2637
+ address: receiver,
2638
+ amount: tokenAmount
2639
+ };
2640
+ }
2641
+ );
2642
+ const viemClient = new ViemClient(chainId, walletClient);
2643
+ const account = new ActaAccount(
2644
+ chainId,
2645
+ viemClient.publicClient(),
2646
+ walletClient
2647
+ );
2648
+ console.log("signing");
2649
+ const { amountExclusive, approval } = yield account.signRecurringOrScheduleBatchPayments({
2650
+ signerAddress,
2651
+ chainId,
2652
+ token: tokenSymbol,
2653
+ feeInclusive: isFeeInclusive,
2654
+ receivers,
2655
+ totalAmount: totalAmountParsed,
2656
+ walletClient,
2657
+ allowMaxTokenApproval,
2658
+ count: 1,
2659
+ feebps: 20
2660
+ });
2661
+ const txn = yield executeScheduleBatchPaymentAPICall(
2662
+ `${envBatchServiceUrl}execute/schedule/batch`,
2663
+ this.APIkey,
2664
+ {
2665
+ senderAddress: signerAddress,
2666
+ chainId,
2667
+ tokenAddress: tokenData.address,
2668
+ amount: (0, import_viem7.toHex)(totalAmountParsed),
2669
+ feeInclusive: isFeeInclusive,
2670
+ serviceType: "batch",
2671
+ amountExclusive: (0, import_viem7.toHex)(amountExclusive),
2672
+ approval,
2673
+ executionAt: executionTime
2674
+ },
2675
+ {
2676
+ sessionId: serviceParams.sessionId
2677
+ }
2678
+ );
2679
+ console.log(txn);
2680
+ return txn.transaction.id;
2681
+ } catch (error) {
2682
+ console.log(error);
2683
+ if (error instanceof Error) {
2684
+ throw new Error(error.message);
2685
+ }
2686
+ throw new Error("Failed to create payment.");
2687
+ }
2688
+ });
2689
+ }
2387
2690
  };
2388
2691
 
2389
2692
  // src/utils.ts
@@ -2399,7 +2702,7 @@ var import_semver = require("semver");
2399
2702
  var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
2400
2703
  var billingServiceUrl = "https://api.acta.link/billing/v1/";
2401
2704
  var depositServiceUrl2 = "https://api.acta.link/deposit/v1/";
2402
- var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2705
+ var transactionServiceUrl4 = "https://api.acta.link/transaction/v1/";
2403
2706
  var toSignerId = (signer) => {
2404
2707
  return (0, import_viem8.encodeAbiParameters)(
2405
2708
  [{ name: "signerData", type: "bytes" }],
@@ -2798,7 +3101,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2798
3101
  });
2799
3102
  console.log(rpcParameters);
2800
3103
  const txn = yield cancelRecurringPaymentAPICall(
2801
- `${transactionServiceUrl3}execute/cancel`,
3104
+ `${transactionServiceUrl4}execute/cancel`,
2802
3105
  rpcParameters,
2803
3106
  {
2804
3107
  chainId,
@@ -2859,6 +3162,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2859
3162
  ethereumUSDC,
2860
3163
  ethereumUSDT,
2861
3164
  ethereumWETH,
3165
+ executeScheduleBatchPaymentAPICall,
2862
3166
  executeSingleBatchPaymentAPICall,
2863
3167
  executeSinglePaymentAPICall,
2864
3168
  fetchBatchInstructionDetails,
@@ -2878,6 +3182,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2878
3182
  lineaETH,
2879
3183
  lineaUSDC,
2880
3184
  lineaWETH,
3185
+ mainnetChains,
2881
3186
  optimismDAI,
2882
3187
  optimismETH,
2883
3188
  optimismUSDC,
@@ -2898,6 +3203,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2898
3203
  serializePermissionAccountParams,
2899
3204
  supportedChains,
2900
3205
  supportedTokensByChain,
3206
+ testnetChains,
2901
3207
  toECDSASigner,
2902
3208
  toPermissionValidator,
2903
3209
  toPolicyId,