@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.js CHANGED
@@ -67,6 +67,8 @@ var supportedChains = [
67
67
  sepolia,
68
68
  polygonAmoy
69
69
  ];
70
+ var mainnetChains = [arbitrum, base, bsc, mainnet, optimism, polygon];
71
+ var testnetChains = [sepolia, baseSepolia, polygonAmoy];
70
72
  function getChainById(chainId) {
71
73
  const chain = supportedChains.find((c) => c.id === chainId);
72
74
  if (!chain) throw new Error(`Chain ${chainId} not supported.`);
@@ -435,7 +437,7 @@ var polygonUSDCe = token({
435
437
  });
436
438
  var polygonTokens = [polygonUSDC, polygonUSDT];
437
439
  var polygonAmoyUSDC = token({
438
- chainId: polygon2.id,
440
+ chainId: polygonAmoy2.id,
439
441
  address: getAddress("0x41E94Eb019C0762f9Bfcf9Fb1E58725BfB0e7582"),
440
442
  decimals: 6,
441
443
  fiatISO: "USDC",
@@ -445,7 +447,7 @@ var polygonAmoyUSDC = token({
445
447
  });
446
448
  var polygonAmoyTokens = [polygonAmoyUSDC];
447
449
  var baseSepoliaUSDC = token({
448
- chainId: polygon2.id,
450
+ chainId: baseSepolia2.id,
449
451
  address: getAddress("0x036CbD53842c5426634e7929541eC2318f3dCF7e"),
450
452
  decimals: 6,
451
453
  fiatISO: "USDC",
@@ -455,7 +457,7 @@ var baseSepoliaUSDC = token({
455
457
  });
456
458
  var baseSepoliaTokens = [baseSepoliaUSDC];
457
459
  var sepoliaUSDC = token({
458
- chainId: polygon2.id,
460
+ chainId: sepolia2.id,
459
461
  address: getAddress("0x1c7D4B196Cb0C7B01d743Fbc6116a902379C7238"),
460
462
  decimals: 6,
461
463
  fiatISO: "USDC",
@@ -591,7 +593,7 @@ import {
591
593
  VALIDATOR_TYPE
592
594
  } from "@zerodev/sdk/constants";
593
595
  import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator";
594
- import { createSmartAccountClient } from "permissionless";
596
+ import { createSmartAccountClient, getRequiredPrefund } from "permissionless";
595
597
  import { createPimlicoClient } from "permissionless/clients/pimlico";
596
598
 
597
599
  // src/rpc.ts
@@ -710,7 +712,7 @@ var ViemClient = class {
710
712
  });
711
713
  const receipt = yield this.publicClient().waitForTransactionReceipt({
712
714
  hash: txn,
713
- confirmations: token2.chainId === 1 ? 1 : 5
715
+ confirmations: token2.chainId === 1 || 11155111 ? 1 : 5
714
716
  });
715
717
  return amount;
716
718
  }
@@ -804,7 +806,8 @@ var ActaAccount = class {
804
806
  chainId,
805
807
  token: tokenSymbol,
806
808
  amount,
807
- receiver
809
+ receiver,
810
+ feebps
808
811
  } = parameters;
809
812
  if (amount <= BigInt(0)) {
810
813
  throw new Error("Amount must be greater than 0.");
@@ -820,11 +823,6 @@ var ActaAccount = class {
820
823
  if (!token2) {
821
824
  throw new Error("Token not found.");
822
825
  }
823
- const quotes = yield pimlicoClient.getTokenQuotes({
824
- tokens: [token2.address],
825
- chain: getChainById(chainId)
826
- });
827
- const { postOpGas, exchangeRate, paymaster } = quotes[0];
828
826
  const userOperation = yield accountClient.prepareUserOperation({
829
827
  calls: [
830
828
  {
@@ -845,22 +843,31 @@ var ActaAccount = class {
845
843
  }
846
844
  ]
847
845
  });
848
- const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
849
- const userOperationMaxCost = BigInt(
850
- userOperationMaxGas * userOperation.maxFeePerGas
851
- );
852
- const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
853
- const ActalinkFeesInToken = amount * BigInt(20) / BigInt(1e4);
854
- const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
846
+ const quotes = yield pimlicoClient.getTokenQuotes({
847
+ tokens: [token2.address],
848
+ chain: getChainById(chainId)
849
+ });
850
+ const userOperationMaxCost = getRequiredPrefund({
851
+ userOperation,
852
+ entryPointVersion: "0.7"
853
+ });
854
+ const postOpGas = quotes[0].postOpGas;
855
+ const exchangeRate = quotes[0].exchangeRate;
856
+ const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd;
857
+ const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
858
+ const costInToken = maxCostInWei * exchangeRate / BigInt(1e18);
859
+ const costInUsd = maxCostInWei * exchangeRateNativeToUsd / BigInt(1e18);
860
+ const ActalinkFeesInToken = amount * BigInt(feebps) / BigInt(1e4);
861
+ const estimatedTotalFeesInToken = costInToken + ActalinkFeesInToken;
855
862
  const feeInclusiveAmountInToken = amount - estimatedTotalFeesInToken;
856
863
  const feeExclusiveAmountInToken = amount + estimatedTotalFeesInToken;
857
864
  return {
858
- estimatedGasCostInToken,
865
+ estimatedGasCostInToken: costInToken,
859
866
  ActalinkFeesInToken,
860
867
  estimatedTotalFeesInToken,
861
868
  feeInclusiveAmountInToken,
862
869
  feeExclusiveAmountInToken,
863
- paymaster,
870
+ paymaster: quotes[0].paymaster,
864
871
  userOperation
865
872
  };
866
873
  });
@@ -874,7 +881,8 @@ var ActaAccount = class {
874
881
  receivers,
875
882
  feeInclusive,
876
883
  walletClient,
877
- totalAmount
884
+ totalAmount,
885
+ feebps
878
886
  } = parameters;
879
887
  if (totalAmount <= BigInt(0)) {
880
888
  throw new Error("Amount must be greater than 0.");
@@ -890,14 +898,6 @@ var ActaAccount = class {
890
898
  if (!token2) {
891
899
  throw new Error("Token not found.");
892
900
  }
893
- console.log(`fromAddress: ${fromAddress}`);
894
- const quotes = yield pimlicoClient.getTokenQuotes({
895
- tokens: [token2.address],
896
- chain: getChainById(chainId)
897
- });
898
- const { postOpGas, exchangeRate, paymaster } = quotes[0];
899
- console.log("preparing");
900
- console.log(token2.address);
901
901
  const receiversData = receivers.map((r) => {
902
902
  return {
903
903
  to: getAddress2(token2.address),
@@ -922,17 +922,27 @@ var ActaAccount = class {
922
922
  }
923
923
  ]
924
924
  });
925
- const userOperationMaxGas = userOperation.preVerificationGas + userOperation.callGasLimit + userOperation.verificationGasLimit + (userOperation.paymasterPostOpGasLimit || BigInt(0)) + (userOperation.paymasterVerificationGasLimit || BigInt(0));
926
- const userOperationMaxCost = BigInt(
927
- userOperationMaxGas * userOperation.maxFeePerGas
928
- );
929
- const estimatedGasCostInToken = (userOperationMaxCost + postOpGas * userOperation.maxFeePerGas) * exchangeRate / BigInt(1e18);
930
- const ActalinkFeesInToken = totalAmount * BigInt(20) / BigInt(1e4);
931
- const estimatedTotalFeesInToken = estimatedGasCostInToken + ActalinkFeesInToken;
925
+ const quotes = yield pimlicoClient.getTokenQuotes({
926
+ tokens: [token2.address],
927
+ chain: getChainById(chainId)
928
+ });
929
+ const userOperationMaxCost = getRequiredPrefund({
930
+ userOperation,
931
+ entryPointVersion: "0.7"
932
+ });
933
+ const postOpGas = quotes[0].postOpGas;
934
+ const exchangeRate = quotes[0].exchangeRate;
935
+ const exchangeRateNativeToUsd = quotes[0].exchangeRateNativeToUsd;
936
+ const paymaster = quotes[0].paymaster;
937
+ const maxCostInWei = userOperationMaxCost + postOpGas * userOperation.maxFeePerGas;
938
+ const costInToken = maxCostInWei * exchangeRate / BigInt(1e18);
939
+ const costInUsd = maxCostInWei * exchangeRateNativeToUsd / BigInt(1e18);
940
+ const ActalinkFeesInToken = totalAmount * BigInt(feebps) / BigInt(1e4);
941
+ const estimatedTotalFeesInToken = costInToken + ActalinkFeesInToken;
932
942
  const feeInclusiveAmountInToken = totalAmount - estimatedTotalFeesInToken;
933
943
  const feeExclusiveAmountInToken = totalAmount + estimatedTotalFeesInToken;
934
944
  return {
935
- estimatedGasCostInToken,
945
+ estimatedGasCostInToken: costInToken,
936
946
  ActalinkFeesInToken,
937
947
  estimatedTotalFeesInToken,
938
948
  feeInclusiveAmountInToken,
@@ -955,7 +965,8 @@ var ActaAccount = class {
955
965
  amount,
956
966
  receiver,
957
967
  feeInclusive,
958
- allowMaxTokenApproval
968
+ allowMaxTokenApproval,
969
+ feebps
959
970
  } = singlePaymentParams;
960
971
  if (amount <= BigInt(0)) {
961
972
  throw new Error("Amount must be greater than 0.");
@@ -981,7 +992,8 @@ var ActaAccount = class {
981
992
  token: tokenSymbol,
982
993
  amount,
983
994
  receiver,
984
- feeInclusive
995
+ feeInclusive,
996
+ feebps
985
997
  });
986
998
  const account = yield this.createAccount();
987
999
  const { accountClient } = yield this.createAccountHelpers();
@@ -1004,7 +1016,7 @@ var ActaAccount = class {
1004
1016
  args: [
1005
1017
  fromAddress,
1006
1018
  "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1007
- estimatedGasCostInToken
1019
+ estimatedTotalFeesInToken
1008
1020
  ]
1009
1021
  },
1010
1022
  {
@@ -1044,7 +1056,8 @@ var ActaAccount = class {
1044
1056
  feeInclusive,
1045
1057
  allowMaxTokenApproval,
1046
1058
  totalAmount,
1047
- walletClient
1059
+ walletClient,
1060
+ feebps
1048
1061
  } = singlePaymentParams;
1049
1062
  if (totalAmount <= BigInt(0)) {
1050
1063
  throw new Error("Amount must be greater than 0.");
@@ -1058,7 +1071,6 @@ var ActaAccount = class {
1058
1071
  }
1059
1072
  const viemClient = new ViemClient(this.chainId, this.signer);
1060
1073
  console.log("validating gas");
1061
- console.log(receivers);
1062
1074
  const {
1063
1075
  estimatedGasCostInToken,
1064
1076
  ActalinkFeesInToken,
@@ -1073,7 +1085,8 @@ var ActaAccount = class {
1073
1085
  receivers,
1074
1086
  feeInclusive,
1075
1087
  totalAmount,
1076
- walletClient
1088
+ walletClient,
1089
+ feebps
1077
1090
  });
1078
1091
  const account = yield this.createAccount();
1079
1092
  const { accountClient } = yield this.createAccountHelpers();
@@ -1142,7 +1155,8 @@ var ActaAccount = class {
1142
1155
  intervalUnit,
1143
1156
  startDate,
1144
1157
  endDate,
1145
- allowMaxTokenApproval
1158
+ allowMaxTokenApproval,
1159
+ feebps
1146
1160
  } = recurringPaymentParams;
1147
1161
  if (amount <= BigInt(0)) {
1148
1162
  throw new Error("Amount must be greater than 0.");
@@ -1192,7 +1206,8 @@ var ActaAccount = class {
1192
1206
  token: tokenSymbol,
1193
1207
  amount,
1194
1208
  receiver,
1195
- feeInclusive
1209
+ feeInclusive,
1210
+ feebps
1196
1211
  });
1197
1212
  const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1198
1213
  const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : amount;
@@ -1257,6 +1272,135 @@ var ActaAccount = class {
1257
1272
  return { approval, amountExclusive };
1258
1273
  });
1259
1274
  }
1275
+ signRecurringOrScheduleBatchPayments(paymentParams) {
1276
+ return __async(this, null, function* () {
1277
+ if (!this.signer) {
1278
+ throw new Error("Signer is required for self custody payments.");
1279
+ }
1280
+ const {
1281
+ signerAddress,
1282
+ chainId,
1283
+ token: tokenSymbol,
1284
+ feeInclusive,
1285
+ count,
1286
+ allowMaxTokenApproval,
1287
+ receivers,
1288
+ totalAmount,
1289
+ walletClient,
1290
+ feebps
1291
+ } = paymentParams;
1292
+ if (signerAddress === void 0) {
1293
+ throw new Error("signer address is not provided.");
1294
+ }
1295
+ if (totalAmount <= BigInt(0)) {
1296
+ throw new Error("Amount must be greater than 0.");
1297
+ }
1298
+ if (receivers.length === 0) {
1299
+ throw new Error("Receivers not found for batch payment");
1300
+ }
1301
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1302
+ if (!token2) {
1303
+ throw new Error("Token not found.");
1304
+ }
1305
+ const kernelVersion = KERNEL_V3_1;
1306
+ const entryPoint = getEntryPoint("0.7");
1307
+ const paymentCount = count != null ? count : 24;
1308
+ const account = yield this.createAccount();
1309
+ const smartAccountAddress = account.address;
1310
+ const viemClient = new ViemClient(this.chainId, this.signer);
1311
+ const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1312
+ const ecdsaValidator = yield signerToEcdsaValidator(
1313
+ viemClient.publicClient(),
1314
+ {
1315
+ entryPoint,
1316
+ kernelVersion,
1317
+ signer: this.signer
1318
+ }
1319
+ );
1320
+ const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1321
+ const emptyAccount = addressToEmptyAccount(sessionKeyAddress);
1322
+ const emptySessionKeySigner = yield toECDSASigner({ signer: emptyAccount });
1323
+ const {
1324
+ estimatedGasCostInToken,
1325
+ ActalinkFeesInToken,
1326
+ feeInclusiveAmountInToken,
1327
+ feeExclusiveAmountInToken,
1328
+ estimatedTotalFeesInToken,
1329
+ paymaster
1330
+ } = yield this.estimateSingleBatchPaymentGas({
1331
+ signerAddress,
1332
+ chainId,
1333
+ token: tokenSymbol,
1334
+ receivers,
1335
+ feeInclusive,
1336
+ totalAmount,
1337
+ walletClient,
1338
+ feebps
1339
+ });
1340
+ const amountToTransfer = feeInclusive ? totalAmount : feeExclusiveAmountInToken;
1341
+ const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : totalAmount;
1342
+ yield viemClient.checkAndApproveToken(
1343
+ token2,
1344
+ smartAccountAddress,
1345
+ amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
1346
+ allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1347
+ );
1348
+ const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
1349
+ const receiversAddress = receivers.map((r) => getAddress2(r.address));
1350
+ const callPolicy = toCallPolicy({
1351
+ policyVersion: CallPolicyVersion.V0_0_4,
1352
+ permissions: [
1353
+ {
1354
+ target: token2.address,
1355
+ valueLimit: BigInt(0),
1356
+ abi: parseAbi2(["function transferFrom(address,address,uint)"]),
1357
+ functionName: "transferFrom",
1358
+ args: [
1359
+ {
1360
+ condition: ParamCondition.EQUAL,
1361
+ value: getAddress2(signerAddress)
1362
+ },
1363
+ {
1364
+ condition: ParamCondition.ONE_OF,
1365
+ value: [
1366
+ "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1367
+ ...receiversAddress
1368
+ ]
1369
+ },
1370
+ {
1371
+ condition: ParamCondition.LESS_THAN_OR_EQUAL,
1372
+ value: amountExclusive
1373
+ }
1374
+ ]
1375
+ }
1376
+ ]
1377
+ });
1378
+ const permissionPlugin = yield toPermissionValidator(
1379
+ viemClient.publicClient(),
1380
+ {
1381
+ entryPoint,
1382
+ kernelVersion,
1383
+ signer: emptySessionKeySigner,
1384
+ policies: [callPolicy]
1385
+ }
1386
+ );
1387
+ const serializedSessionKeyAccount = yield createKernelAccount(
1388
+ viemClient.publicClient(),
1389
+ {
1390
+ entryPoint,
1391
+ kernelVersion,
1392
+ plugins: {
1393
+ sudo: ecdsaValidator,
1394
+ regular: permissionPlugin
1395
+ }
1396
+ }
1397
+ );
1398
+ const approval = yield serializePermissionAccount(
1399
+ serializedSessionKeyAccount
1400
+ );
1401
+ return { approval, amountExclusive };
1402
+ });
1403
+ }
1260
1404
  signRecurringTransactionCancellation(paymentCancellationParams) {
1261
1405
  return __async(this, null, function* () {
1262
1406
  var _a;
@@ -1504,6 +1648,23 @@ function executeSingleBatchPaymentAPICall(url, APIKey, userOperation, paymentPar
1504
1648
  return response.data;
1505
1649
  });
1506
1650
  }
1651
+ function executeScheduleBatchPaymentAPICall(url, APIKey, paymentParams, serviceParams) {
1652
+ return __async(this, null, function* () {
1653
+ const params = {
1654
+ paymentParams,
1655
+ serviceParams
1656
+ };
1657
+ const response = yield sendRequest({
1658
+ url,
1659
+ method: "post" /* Post */,
1660
+ body: params,
1661
+ headers: {
1662
+ "x-api-key": APIKey
1663
+ }
1664
+ });
1665
+ return response.data;
1666
+ });
1667
+ }
1507
1668
  function fetchRecurringTransactionWithId(url) {
1508
1669
  return __async(this, null, function* () {
1509
1670
  const response = yield sendRequest({ url, method: "get" /* Get */ });
@@ -1556,6 +1717,7 @@ var transactionServiceUrl = "https://api.acta.link/transaction/v1/";
1556
1717
  var depositServiceUrl = "https://api.acta.link/deposit/v1/";
1557
1718
  var ActaDeposit = class {
1558
1719
  constructor(parameters) {
1720
+ this.feeInclusive = false;
1559
1721
  this.count = 0;
1560
1722
  this.intervalUnit = void 0;
1561
1723
  this.startDate = void 0;
@@ -1565,7 +1727,7 @@ var ActaDeposit = class {
1565
1727
  this.status = "not_started";
1566
1728
  this.serviceType = "deposit";
1567
1729
  this.allowMaxTokenApproval = false;
1568
- var _a, _b;
1730
+ var _a, _b, _c;
1569
1731
  this.connectorType = parameters.connectorType;
1570
1732
  this.walletClient = parameters.walletClient;
1571
1733
  this.signerAddress = parameters.signerAddress;
@@ -1573,14 +1735,14 @@ var ActaDeposit = class {
1573
1735
  this.token = parameters.token;
1574
1736
  this.amount = parameters.amount;
1575
1737
  this.receiver = parameters.receiver;
1576
- this.feeInclusive = parameters.feeInclusive;
1738
+ this.feeInclusive = (_a = parameters.feeInclusive) != null ? _a : false;
1577
1739
  this.paymentType = parameters.paymentType;
1578
1740
  this.count = parameters.count;
1579
1741
  this.intervalUnit = parameters.intervalUnit;
1580
1742
  this.startDate = parameters.startDate;
1581
1743
  this.endDate = parameters.endDate;
1582
- this.depositSessionId = (_a = parameters.depositSessionId) != null ? _a : "";
1583
- this.allowMaxTokenApproval = (_b = parameters.allowMaxTokenApproval) != null ? _b : false;
1744
+ this.depositSessionId = (_b = parameters.depositSessionId) != null ? _b : "";
1745
+ this.allowMaxTokenApproval = (_c = parameters.allowMaxTokenApproval) != null ? _c : false;
1584
1746
  this.viemClient = new ViemClient(this.chainId, this.walletClient);
1585
1747
  this.account = new ActaAccount(
1586
1748
  this.chainId,
@@ -1745,7 +1907,8 @@ var ActaDeposit = class {
1745
1907
  amount,
1746
1908
  receiver,
1747
1909
  feeInclusive,
1748
- allowMaxTokenApproval: this.allowMaxTokenApproval
1910
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
1911
+ feebps: 10
1749
1912
  });
1750
1913
  const txn = yield executeSinglePaymentAPICall(
1751
1914
  `${transactionServiceUrl}execute/single`,
@@ -1838,7 +2001,8 @@ var ActaDeposit = class {
1838
2001
  startDate,
1839
2002
  endDate,
1840
2003
  receiver,
1841
- allowMaxTokenApproval: this.allowMaxTokenApproval
2004
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
2005
+ feebps: 20
1842
2006
  });
1843
2007
  const txn = yield scheduleRecurringPaymentsAPICall(
1844
2008
  `${transactionServiceUrl}schedule/recurring`,
@@ -1881,7 +2045,8 @@ var ActaDeposit = class {
1881
2045
  feeInclusive,
1882
2046
  receiver,
1883
2047
  signerAddress,
1884
- token: tokenSymbol
2048
+ token: tokenSymbol,
2049
+ feebps: 10
1885
2050
  });
1886
2051
  const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1887
2052
  let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
@@ -1901,6 +2066,7 @@ import { toHex as toHex3 } from "viem";
1901
2066
  var transactionServiceUrl2 = "https://api.acta.link/transaction/v1/";
1902
2067
  var ActaBilling = class {
1903
2068
  constructor(parameters) {
2069
+ this.feeInclusive = true;
1904
2070
  this.count = 0;
1905
2071
  this.intervalUnit = void 0;
1906
2072
  this.startDate = void 0;
@@ -1909,7 +2075,7 @@ var ActaBilling = class {
1909
2075
  this.status = "not_started";
1910
2076
  this.serviceType = "deposit";
1911
2077
  this.allowMaxTokenApproval = false;
1912
- var _a;
2078
+ var _a, _b;
1913
2079
  this.connectorType = parameters.connectorType;
1914
2080
  this.walletClient = parameters.walletClient;
1915
2081
  this.signerAddress = parameters.signerAddress;
@@ -1917,13 +2083,13 @@ var ActaBilling = class {
1917
2083
  this.token = parameters.token;
1918
2084
  this.amount = parameters.amount;
1919
2085
  this.receiver = parameters.receiver;
1920
- this.feeInclusive = parameters.feeInclusive;
2086
+ this.feeInclusive = (_a = parameters.feeInclusive) != null ? _a : true;
1921
2087
  this.paymentType = parameters.paymentType;
1922
2088
  this.count = parameters.count;
1923
2089
  this.intervalUnit = parameters.intervalUnit;
1924
2090
  this.startDate = parameters.startDate;
1925
2091
  this.endDate = parameters.endDate;
1926
- this.allowMaxTokenApproval = (_a = parameters.allowMaxTokenApproval) != null ? _a : false;
2092
+ this.allowMaxTokenApproval = (_b = parameters.allowMaxTokenApproval) != null ? _b : false;
1927
2093
  this.serviceType = parameters.serviceType;
1928
2094
  this.viemClient = new ViemClient(this.chainId, this.walletClient);
1929
2095
  this.account = new ActaAccount(
@@ -1991,7 +2157,8 @@ var ActaBilling = class {
1991
2157
  amount,
1992
2158
  receiver,
1993
2159
  feeInclusive,
1994
- allowMaxTokenApproval: this.allowMaxTokenApproval
2160
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
2161
+ feebps: 20
1995
2162
  });
1996
2163
  const txn = yield executeSinglePaymentAPICall(
1997
2164
  `${transactionServiceUrl2}execute/single`,
@@ -2056,7 +2223,8 @@ var ActaBilling = class {
2056
2223
  startDate,
2057
2224
  endDate,
2058
2225
  receiver,
2059
- allowMaxTokenApproval: this.allowMaxTokenApproval
2226
+ allowMaxTokenApproval: this.allowMaxTokenApproval,
2227
+ feebps: 20
2060
2228
  });
2061
2229
  const txn = yield scheduleRecurringPaymentsAPICall(
2062
2230
  `${transactionServiceUrl2}schedule/recurring`,
@@ -2099,7 +2267,8 @@ var ActaBilling = class {
2099
2267
  feeInclusive,
2100
2268
  receiver,
2101
2269
  signerAddress,
2102
- token: tokenSymbol
2270
+ token: tokenSymbol,
2271
+ feebps: 20
2103
2272
  });
2104
2273
  const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
2105
2274
  let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
@@ -2121,7 +2290,28 @@ import {
2121
2290
  toHex as toHex4,
2122
2291
  zeroAddress as zeroAddress5
2123
2292
  } from "viem";
2293
+ var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2124
2294
  var batchServiceUrl = "https://api.acta.link/batch/api/v1/";
2295
+ var transactionServiceTestUrl = "https://api.acta.link/transaction/test/v1/";
2296
+ var batchServiceTestUrl = "https://api.acta.link/batch/test/api/v1/";
2297
+ var returnEnvUrl = (chainId) => {
2298
+ const mainnetChain = mainnetChains.find((c) => c.id === chainId);
2299
+ const testnetChain = testnetChains.find((c) => c.id === chainId);
2300
+ if (!mainnetChain && !testnetChain) {
2301
+ throw new Error(`Chain ${chainId} not supported.`);
2302
+ }
2303
+ if (mainnetChain) {
2304
+ return {
2305
+ envTransactionServiceUrl: transactionServiceUrl3,
2306
+ envBatchServiceUrl: batchServiceUrl
2307
+ };
2308
+ } else {
2309
+ return {
2310
+ envTransactionServiceUrl: transactionServiceTestUrl,
2311
+ envBatchServiceUrl: batchServiceTestUrl
2312
+ };
2313
+ }
2314
+ };
2125
2315
  var ActaBatch = class {
2126
2316
  constructor(parameters) {
2127
2317
  this.APIkey = parameters.APIKey;
@@ -2142,8 +2332,9 @@ var ActaBatch = class {
2142
2332
  if (!instructionId || instructionId === "") {
2143
2333
  throw new Error("Instruction id is required");
2144
2334
  }
2335
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2145
2336
  const session = yield createBatchSessionAPICall(
2146
- `${batchServiceUrl}create/session`,
2337
+ `${envBatchServiceUrl}create/session`,
2147
2338
  this.APIkey,
2148
2339
  {
2149
2340
  name,
@@ -2175,8 +2366,13 @@ var ActaBatch = class {
2175
2366
  walletClient,
2176
2367
  instructionId
2177
2368
  } = parameters;
2369
+ let isFeeInclusive = false;
2370
+ if (feeInclusive) {
2371
+ isFeeInclusive = true;
2372
+ }
2373
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2178
2374
  const instuctionData = yield fetchBatchInstructionDetails(
2179
- `${batchServiceUrl}instruction/${instructionId}`,
2375
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2180
2376
  this.APIkey
2181
2377
  );
2182
2378
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2216,12 +2412,13 @@ var ActaBatch = class {
2216
2412
  userOperation
2217
2413
  } = yield account.estimateSingleBatchPaymentGas({
2218
2414
  chainId,
2219
- feeInclusive,
2415
+ feeInclusive: isFeeInclusive,
2220
2416
  signerAddress,
2221
2417
  token: token2,
2222
2418
  walletClient,
2223
2419
  receivers,
2224
- totalAmount: totalAmountParsed
2420
+ totalAmount: totalAmountParsed,
2421
+ feebps: 20
2225
2422
  });
2226
2423
  return {
2227
2424
  estimatedGasCostInToken,
@@ -2252,8 +2449,13 @@ var ActaBatch = class {
2252
2449
  allowMaxTokenApproval,
2253
2450
  instructionId
2254
2451
  } = params;
2452
+ let isFeeInclusive = false;
2453
+ if (feeInclusive) {
2454
+ isFeeInclusive = true;
2455
+ }
2456
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2255
2457
  const instuctionData = yield fetchBatchInstructionDetails(
2256
- `${batchServiceUrl}instruction/${instructionId}`,
2458
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2257
2459
  this.APIkey
2258
2460
  );
2259
2461
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2289,14 +2491,15 @@ var ActaBatch = class {
2289
2491
  signerAddress,
2290
2492
  chainId,
2291
2493
  token: tokenSymbol,
2292
- feeInclusive,
2494
+ feeInclusive: isFeeInclusive,
2293
2495
  receivers,
2294
2496
  totalAmount: totalAmountParsed,
2295
2497
  walletClient,
2296
- allowMaxTokenApproval
2498
+ allowMaxTokenApproval,
2499
+ feebps: 20
2297
2500
  });
2298
2501
  const txn = yield executeSingleBatchPaymentAPICall(
2299
- `${batchServiceUrl}execute/single/batch`,
2502
+ `${envBatchServiceUrl}execute/single/batch`,
2300
2503
  this.APIkey,
2301
2504
  rpcParameters,
2302
2505
  {
@@ -2304,7 +2507,7 @@ var ActaBatch = class {
2304
2507
  chainId,
2305
2508
  tokenAddress: tokenData.address,
2306
2509
  amount: toHex4(totalAmountParsed),
2307
- feeInclusive,
2510
+ feeInclusive: isFeeInclusive,
2308
2511
  serviceType: "batch"
2309
2512
  },
2310
2513
  serviceParams
@@ -2319,6 +2522,103 @@ var ActaBatch = class {
2319
2522
  }
2320
2523
  });
2321
2524
  }
2525
+ createScheduleBatchPayment(params, serviceParams) {
2526
+ return __async(this, null, function* () {
2527
+ try {
2528
+ const {
2529
+ chainId,
2530
+ feeInclusive,
2531
+ signerAddress,
2532
+ token: tokenSymbol,
2533
+ walletClient,
2534
+ allowMaxTokenApproval,
2535
+ instructionId,
2536
+ executionTime
2537
+ } = params;
2538
+ let isFeeInclusive = false;
2539
+ if (feeInclusive) {
2540
+ isFeeInclusive = true;
2541
+ }
2542
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2543
+ if (executionTime <= Date.now() + 1e3 * 60 * 2) {
2544
+ throw new Error(
2545
+ "Execution time must be more than 5 mins from current time."
2546
+ );
2547
+ }
2548
+ const instuctionData = yield fetchBatchInstructionDetails(
2549
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2550
+ this.APIkey
2551
+ );
2552
+ if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
2553
+ throw new Error("Instruction not found");
2554
+ }
2555
+ console.log(instuctionData);
2556
+ const tokenData = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2557
+ if (!tokenData) {
2558
+ throw new Error("Token not supported");
2559
+ }
2560
+ const totalAmount = instuctionData.totalAmount;
2561
+ const totalAmountParsed = BigInt(
2562
+ parseUnits(totalAmount, tokenData.decimals)
2563
+ );
2564
+ const receivers = instuctionData.receivers.map(
2565
+ (i) => {
2566
+ const receiver = getAddress3(i.address);
2567
+ const tokenAmount = BigInt(parseUnits(i.amount, tokenData.decimals));
2568
+ return {
2569
+ address: receiver,
2570
+ amount: tokenAmount
2571
+ };
2572
+ }
2573
+ );
2574
+ const viemClient = new ViemClient(chainId, walletClient);
2575
+ const account = new ActaAccount(
2576
+ chainId,
2577
+ viemClient.publicClient(),
2578
+ walletClient
2579
+ );
2580
+ console.log("signing");
2581
+ const { amountExclusive, approval } = yield account.signRecurringOrScheduleBatchPayments({
2582
+ signerAddress,
2583
+ chainId,
2584
+ token: tokenSymbol,
2585
+ feeInclusive: isFeeInclusive,
2586
+ receivers,
2587
+ totalAmount: totalAmountParsed,
2588
+ walletClient,
2589
+ allowMaxTokenApproval,
2590
+ count: 1,
2591
+ feebps: 20
2592
+ });
2593
+ const txn = yield executeScheduleBatchPaymentAPICall(
2594
+ `${envBatchServiceUrl}execute/schedule/batch`,
2595
+ this.APIkey,
2596
+ {
2597
+ senderAddress: signerAddress,
2598
+ chainId,
2599
+ tokenAddress: tokenData.address,
2600
+ amount: toHex4(totalAmountParsed),
2601
+ feeInclusive: isFeeInclusive,
2602
+ serviceType: "batch",
2603
+ amountExclusive: toHex4(amountExclusive),
2604
+ approval,
2605
+ executionAt: executionTime
2606
+ },
2607
+ {
2608
+ sessionId: serviceParams.sessionId
2609
+ }
2610
+ );
2611
+ console.log(txn);
2612
+ return txn.transaction.id;
2613
+ } catch (error) {
2614
+ console.log(error);
2615
+ if (error instanceof Error) {
2616
+ throw new Error(error.message);
2617
+ }
2618
+ throw new Error("Failed to create payment.");
2619
+ }
2620
+ });
2621
+ }
2322
2622
  };
2323
2623
 
2324
2624
  // src/utils.ts
@@ -2365,7 +2665,7 @@ import { coerce, gt } from "semver";
2365
2665
  var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
2366
2666
  var billingServiceUrl = "https://api.acta.link/billing/v1/";
2367
2667
  var depositServiceUrl2 = "https://api.acta.link/deposit/v1/";
2368
- var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2668
+ var transactionServiceUrl4 = "https://api.acta.link/transaction/v1/";
2369
2669
  var toSignerId = (signer) => {
2370
2670
  return encodeAbiParameters(
2371
2671
  [{ name: "signerData", type: "bytes" }],
@@ -2764,7 +3064,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2764
3064
  });
2765
3065
  console.log(rpcParameters);
2766
3066
  const txn = yield cancelRecurringPaymentAPICall(
2767
- `${transactionServiceUrl3}execute/cancel`,
3067
+ `${transactionServiceUrl4}execute/cancel`,
2768
3068
  rpcParameters,
2769
3069
  {
2770
3070
  chainId,
@@ -2824,6 +3124,7 @@ export {
2824
3124
  ethereumUSDC,
2825
3125
  ethereumUSDT,
2826
3126
  ethereumWETH,
3127
+ executeScheduleBatchPaymentAPICall,
2827
3128
  executeSingleBatchPaymentAPICall,
2828
3129
  executeSinglePaymentAPICall,
2829
3130
  fetchBatchInstructionDetails,
@@ -2843,6 +3144,7 @@ export {
2843
3144
  lineaETH,
2844
3145
  lineaUSDC,
2845
3146
  lineaWETH,
3147
+ mainnetChains,
2846
3148
  optimismDAI,
2847
3149
  optimismETH,
2848
3150
  optimismUSDC,
@@ -2863,6 +3165,7 @@ export {
2863
3165
  serializePermissionAccountParams,
2864
3166
  supportedChains,
2865
3167
  supportedTokensByChain,
3168
+ testnetChains,
2866
3169
  toECDSASigner2 as toECDSASigner,
2867
3170
  toPermissionValidator2 as toPermissionValidator,
2868
3171
  toPolicyId,