@actalink/commonlib 0.0.14 → 0.0.15

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
  }
@@ -1128,7 +1133,6 @@ var ActaAccount = class {
1128
1133
  }
1129
1134
  const viemClient = new ViemClient(this.chainId, this.signer);
1130
1135
  console.log("validating gas");
1131
- console.log(receivers);
1132
1136
  const {
1133
1137
  estimatedGasCostInToken,
1134
1138
  ActalinkFeesInToken,
@@ -1327,6 +1331,133 @@ var ActaAccount = class {
1327
1331
  return { approval, amountExclusive };
1328
1332
  });
1329
1333
  }
1334
+ signRecurringOrScheduleBatchPayments(paymentParams) {
1335
+ return __async(this, null, function* () {
1336
+ if (!this.signer) {
1337
+ throw new Error("Signer is required for self custody payments.");
1338
+ }
1339
+ const {
1340
+ signerAddress,
1341
+ chainId,
1342
+ token: tokenSymbol,
1343
+ feeInclusive,
1344
+ count,
1345
+ allowMaxTokenApproval,
1346
+ receivers,
1347
+ totalAmount,
1348
+ walletClient
1349
+ } = paymentParams;
1350
+ if (signerAddress === void 0) {
1351
+ throw new Error("signer address is not provided.");
1352
+ }
1353
+ if (totalAmount <= BigInt(0)) {
1354
+ throw new Error("Amount must be greater than 0.");
1355
+ }
1356
+ if (receivers.length === 0) {
1357
+ throw new Error("Receivers not found for batch payment");
1358
+ }
1359
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1360
+ if (!token2) {
1361
+ throw new Error("Token not found.");
1362
+ }
1363
+ const kernelVersion = import_constants.KERNEL_V3_1;
1364
+ const entryPoint = (0, import_constants.getEntryPoint)("0.7");
1365
+ const paymentCount = count != null ? count : 24;
1366
+ const account = yield this.createAccount();
1367
+ const smartAccountAddress = account.address;
1368
+ const viemClient = new ViemClient(this.chainId, this.signer);
1369
+ const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1370
+ const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(
1371
+ viemClient.publicClient(),
1372
+ {
1373
+ entryPoint,
1374
+ kernelVersion,
1375
+ signer: this.signer
1376
+ }
1377
+ );
1378
+ const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1379
+ const emptyAccount = (0, import_sdk.addressToEmptyAccount)(sessionKeyAddress);
1380
+ const emptySessionKeySigner = yield (0, import_signers.toECDSASigner)({ signer: emptyAccount });
1381
+ const {
1382
+ estimatedGasCostInToken,
1383
+ ActalinkFeesInToken,
1384
+ feeInclusiveAmountInToken,
1385
+ feeExclusiveAmountInToken,
1386
+ estimatedTotalFeesInToken,
1387
+ paymaster
1388
+ } = yield this.estimateSingleBatchPaymentGas({
1389
+ signerAddress,
1390
+ chainId,
1391
+ token: tokenSymbol,
1392
+ receivers,
1393
+ feeInclusive,
1394
+ totalAmount,
1395
+ walletClient
1396
+ });
1397
+ const amountToTransfer = feeInclusive ? totalAmount : feeExclusiveAmountInToken;
1398
+ const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : totalAmount;
1399
+ yield viemClient.checkAndApproveToken(
1400
+ token2,
1401
+ smartAccountAddress,
1402
+ amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
1403
+ allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1404
+ );
1405
+ const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
1406
+ const receiversAddress = receivers.map((r) => (0, import_viem3.getAddress)(r.address));
1407
+ const callPolicy = (0, import_policies.toCallPolicy)({
1408
+ policyVersion: import_policies.CallPolicyVersion.V0_0_4,
1409
+ permissions: [
1410
+ {
1411
+ target: token2.address,
1412
+ valueLimit: BigInt(0),
1413
+ abi: (0, import_viem3.parseAbi)(["function transferFrom(address,address,uint)"]),
1414
+ functionName: "transferFrom",
1415
+ args: [
1416
+ {
1417
+ condition: import_policies.ParamCondition.EQUAL,
1418
+ value: (0, import_viem3.getAddress)(signerAddress)
1419
+ },
1420
+ {
1421
+ condition: import_policies.ParamCondition.ONE_OF,
1422
+ value: [
1423
+ "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1424
+ ...receiversAddress
1425
+ ]
1426
+ },
1427
+ {
1428
+ condition: import_policies.ParamCondition.LESS_THAN_OR_EQUAL,
1429
+ value: amountExclusive
1430
+ }
1431
+ ]
1432
+ }
1433
+ ]
1434
+ });
1435
+ const permissionPlugin = yield (0, import_permissions.toPermissionValidator)(
1436
+ viemClient.publicClient(),
1437
+ {
1438
+ entryPoint,
1439
+ kernelVersion,
1440
+ signer: emptySessionKeySigner,
1441
+ policies: [callPolicy]
1442
+ }
1443
+ );
1444
+ const serializedSessionKeyAccount = yield (0, import_sdk.createKernelAccount)(
1445
+ viemClient.publicClient(),
1446
+ {
1447
+ entryPoint,
1448
+ kernelVersion,
1449
+ plugins: {
1450
+ sudo: ecdsaValidator,
1451
+ regular: permissionPlugin
1452
+ }
1453
+ }
1454
+ );
1455
+ const approval = yield (0, import_permissions.serializePermissionAccount)(
1456
+ serializedSessionKeyAccount
1457
+ );
1458
+ return { approval, amountExclusive };
1459
+ });
1460
+ }
1330
1461
  signRecurringTransactionCancellation(paymentCancellationParams) {
1331
1462
  return __async(this, null, function* () {
1332
1463
  var _a;
@@ -1574,6 +1705,23 @@ function executeSingleBatchPaymentAPICall(url, APIKey, userOperation, paymentPar
1574
1705
  return response.data;
1575
1706
  });
1576
1707
  }
1708
+ function executeScheduleBatchPaymentAPICall(url, APIKey, paymentParams, serviceParams) {
1709
+ return __async(this, null, function* () {
1710
+ const params = {
1711
+ paymentParams,
1712
+ serviceParams
1713
+ };
1714
+ const response = yield sendRequest({
1715
+ url,
1716
+ method: "post" /* Post */,
1717
+ body: params,
1718
+ headers: {
1719
+ "x-api-key": APIKey
1720
+ }
1721
+ });
1722
+ return response.data;
1723
+ });
1724
+ }
1577
1725
  function fetchRecurringTransactionWithId(url) {
1578
1726
  return __async(this, null, function* () {
1579
1727
  const response = yield sendRequest({ url, method: "get" /* Get */ });
@@ -2186,7 +2334,28 @@ var ActaBilling = class {
2186
2334
 
2187
2335
  // src/batch.ts
2188
2336
  var import_viem7 = require("viem");
2337
+ var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2189
2338
  var batchServiceUrl = "https://api.acta.link/batch/api/v1/";
2339
+ var transactionServiceTestUrl = "https://api.acta.link/transaction/test/v1/";
2340
+ var batchServiceTestUrl = "https://api.acta.link/batch/test/api/v1/";
2341
+ var returnEnvUrl = (chainId) => {
2342
+ const mainnetChain = mainnetChains.find((c) => c.id === chainId);
2343
+ const testnetChain = testnetChains.find((c) => c.id === chainId);
2344
+ if (!mainnetChain && !testnetChain) {
2345
+ throw new Error(`Chain ${chainId} not supported.`);
2346
+ }
2347
+ if (mainnetChain) {
2348
+ return {
2349
+ envTransactionServiceUrl: transactionServiceUrl3,
2350
+ envBatchServiceUrl: batchServiceUrl
2351
+ };
2352
+ } else {
2353
+ return {
2354
+ envTransactionServiceUrl: transactionServiceTestUrl,
2355
+ envBatchServiceUrl: batchServiceTestUrl
2356
+ };
2357
+ }
2358
+ };
2190
2359
  var ActaBatch = class {
2191
2360
  constructor(parameters) {
2192
2361
  this.APIkey = parameters.APIKey;
@@ -2207,8 +2376,9 @@ var ActaBatch = class {
2207
2376
  if (!instructionId || instructionId === "") {
2208
2377
  throw new Error("Instruction id is required");
2209
2378
  }
2379
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2210
2380
  const session = yield createBatchSessionAPICall(
2211
- `${batchServiceUrl}create/session`,
2381
+ `${envBatchServiceUrl}create/session`,
2212
2382
  this.APIkey,
2213
2383
  {
2214
2384
  name,
@@ -2240,8 +2410,9 @@ var ActaBatch = class {
2240
2410
  walletClient,
2241
2411
  instructionId
2242
2412
  } = parameters;
2413
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2243
2414
  const instuctionData = yield fetchBatchInstructionDetails(
2244
- `${batchServiceUrl}instruction/${instructionId}`,
2415
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2245
2416
  this.APIkey
2246
2417
  );
2247
2418
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2317,8 +2488,9 @@ var ActaBatch = class {
2317
2488
  allowMaxTokenApproval,
2318
2489
  instructionId
2319
2490
  } = params;
2491
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2320
2492
  const instuctionData = yield fetchBatchInstructionDetails(
2321
- `${batchServiceUrl}instruction/${instructionId}`,
2493
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2322
2494
  this.APIkey
2323
2495
  );
2324
2496
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2361,7 +2533,7 @@ var ActaBatch = class {
2361
2533
  allowMaxTokenApproval
2362
2534
  });
2363
2535
  const txn = yield executeSingleBatchPaymentAPICall(
2364
- `${batchServiceUrl}execute/single/batch`,
2536
+ `${envBatchServiceUrl}execute/single/batch`,
2365
2537
  this.APIkey,
2366
2538
  rpcParameters,
2367
2539
  {
@@ -2384,6 +2556,98 @@ var ActaBatch = class {
2384
2556
  }
2385
2557
  });
2386
2558
  }
2559
+ createScheduleBatchPayment(params, serviceParams) {
2560
+ return __async(this, null, function* () {
2561
+ try {
2562
+ const {
2563
+ chainId,
2564
+ feeInclusive,
2565
+ signerAddress,
2566
+ token: tokenSymbol,
2567
+ walletClient,
2568
+ allowMaxTokenApproval,
2569
+ instructionId,
2570
+ executionTime
2571
+ } = params;
2572
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2573
+ if (executionTime <= Date.now() + 1e3 * 60 * 2) {
2574
+ throw new Error(
2575
+ "Execution time must be more than 5 mins from current time."
2576
+ );
2577
+ }
2578
+ const instuctionData = yield fetchBatchInstructionDetails(
2579
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2580
+ this.APIkey
2581
+ );
2582
+ if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
2583
+ throw new Error("Instruction not found");
2584
+ }
2585
+ console.log(instuctionData);
2586
+ const tokenData = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2587
+ if (!tokenData) {
2588
+ throw new Error("Token not supported");
2589
+ }
2590
+ const totalAmount = instuctionData.totalAmount;
2591
+ const totalAmountParsed = BigInt(
2592
+ (0, import_viem7.parseUnits)(totalAmount, tokenData.decimals)
2593
+ );
2594
+ const receivers = instuctionData.receivers.map(
2595
+ (i) => {
2596
+ const receiver = (0, import_viem7.getAddress)(i.address);
2597
+ const tokenAmount = BigInt((0, import_viem7.parseUnits)(i.amount, tokenData.decimals));
2598
+ return {
2599
+ address: receiver,
2600
+ amount: tokenAmount
2601
+ };
2602
+ }
2603
+ );
2604
+ const viemClient = new ViemClient(chainId, walletClient);
2605
+ const account = new ActaAccount(
2606
+ chainId,
2607
+ viemClient.publicClient(),
2608
+ walletClient
2609
+ );
2610
+ console.log("signing");
2611
+ const { amountExclusive, approval } = yield account.signRecurringOrScheduleBatchPayments({
2612
+ signerAddress,
2613
+ chainId,
2614
+ token: tokenSymbol,
2615
+ feeInclusive,
2616
+ receivers,
2617
+ totalAmount: totalAmountParsed,
2618
+ walletClient,
2619
+ allowMaxTokenApproval,
2620
+ count: 1
2621
+ });
2622
+ const txn = yield executeScheduleBatchPaymentAPICall(
2623
+ `${envBatchServiceUrl}execute/schedule/batch`,
2624
+ this.APIkey,
2625
+ {
2626
+ senderAddress: signerAddress,
2627
+ chainId,
2628
+ tokenAddress: tokenData.address,
2629
+ amount: (0, import_viem7.toHex)(totalAmountParsed),
2630
+ feeInclusive,
2631
+ serviceType: "batch",
2632
+ amountExclusive: (0, import_viem7.toHex)(amountExclusive),
2633
+ approval,
2634
+ executionAt: executionTime
2635
+ },
2636
+ {
2637
+ sessionId: serviceParams.sessionId
2638
+ }
2639
+ );
2640
+ console.log(txn);
2641
+ return txn.transaction.id;
2642
+ } catch (error) {
2643
+ console.log(error);
2644
+ if (error instanceof Error) {
2645
+ throw new Error(error.message);
2646
+ }
2647
+ throw new Error("Failed to create payment.");
2648
+ }
2649
+ });
2650
+ }
2387
2651
  };
2388
2652
 
2389
2653
  // src/utils.ts
@@ -2399,7 +2663,7 @@ var import_semver = require("semver");
2399
2663
  var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
2400
2664
  var billingServiceUrl = "https://api.acta.link/billing/v1/";
2401
2665
  var depositServiceUrl2 = "https://api.acta.link/deposit/v1/";
2402
- var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2666
+ var transactionServiceUrl4 = "https://api.acta.link/transaction/v1/";
2403
2667
  var toSignerId = (signer) => {
2404
2668
  return (0, import_viem8.encodeAbiParameters)(
2405
2669
  [{ name: "signerData", type: "bytes" }],
@@ -2798,7 +3062,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2798
3062
  });
2799
3063
  console.log(rpcParameters);
2800
3064
  const txn = yield cancelRecurringPaymentAPICall(
2801
- `${transactionServiceUrl3}execute/cancel`,
3065
+ `${transactionServiceUrl4}execute/cancel`,
2802
3066
  rpcParameters,
2803
3067
  {
2804
3068
  chainId,
@@ -2859,6 +3123,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2859
3123
  ethereumUSDC,
2860
3124
  ethereumUSDT,
2861
3125
  ethereumWETH,
3126
+ executeScheduleBatchPaymentAPICall,
2862
3127
  executeSingleBatchPaymentAPICall,
2863
3128
  executeSinglePaymentAPICall,
2864
3129
  fetchBatchInstructionDetails,
@@ -2878,6 +3143,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2878
3143
  lineaETH,
2879
3144
  lineaUSDC,
2880
3145
  lineaWETH,
3146
+ mainnetChains,
2881
3147
  optimismDAI,
2882
3148
  optimismETH,
2883
3149
  optimismUSDC,
@@ -2898,6 +3164,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2898
3164
  serializePermissionAccountParams,
2899
3165
  supportedChains,
2900
3166
  supportedTokensByChain,
3167
+ testnetChains,
2901
3168
  toECDSASigner,
2902
3169
  toPermissionValidator,
2903
3170
  toPolicyId,