@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.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",
@@ -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
  }
@@ -1058,7 +1060,6 @@ var ActaAccount = class {
1058
1060
  }
1059
1061
  const viemClient = new ViemClient(this.chainId, this.signer);
1060
1062
  console.log("validating gas");
1061
- console.log(receivers);
1062
1063
  const {
1063
1064
  estimatedGasCostInToken,
1064
1065
  ActalinkFeesInToken,
@@ -1257,6 +1258,133 @@ var ActaAccount = class {
1257
1258
  return { approval, amountExclusive };
1258
1259
  });
1259
1260
  }
1261
+ signRecurringOrScheduleBatchPayments(paymentParams) {
1262
+ return __async(this, null, function* () {
1263
+ if (!this.signer) {
1264
+ throw new Error("Signer is required for self custody payments.");
1265
+ }
1266
+ const {
1267
+ signerAddress,
1268
+ chainId,
1269
+ token: tokenSymbol,
1270
+ feeInclusive,
1271
+ count,
1272
+ allowMaxTokenApproval,
1273
+ receivers,
1274
+ totalAmount,
1275
+ walletClient
1276
+ } = paymentParams;
1277
+ if (signerAddress === void 0) {
1278
+ throw new Error("signer address is not provided.");
1279
+ }
1280
+ if (totalAmount <= BigInt(0)) {
1281
+ throw new Error("Amount must be greater than 0.");
1282
+ }
1283
+ if (receivers.length === 0) {
1284
+ throw new Error("Receivers not found for batch payment");
1285
+ }
1286
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1287
+ if (!token2) {
1288
+ throw new Error("Token not found.");
1289
+ }
1290
+ const kernelVersion = KERNEL_V3_1;
1291
+ const entryPoint = getEntryPoint("0.7");
1292
+ const paymentCount = count != null ? count : 24;
1293
+ const account = yield this.createAccount();
1294
+ const smartAccountAddress = account.address;
1295
+ const viemClient = new ViemClient(this.chainId, this.signer);
1296
+ const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1297
+ const ecdsaValidator = yield signerToEcdsaValidator(
1298
+ viemClient.publicClient(),
1299
+ {
1300
+ entryPoint,
1301
+ kernelVersion,
1302
+ signer: this.signer
1303
+ }
1304
+ );
1305
+ const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1306
+ const emptyAccount = addressToEmptyAccount(sessionKeyAddress);
1307
+ const emptySessionKeySigner = yield toECDSASigner({ signer: emptyAccount });
1308
+ const {
1309
+ estimatedGasCostInToken,
1310
+ ActalinkFeesInToken,
1311
+ feeInclusiveAmountInToken,
1312
+ feeExclusiveAmountInToken,
1313
+ estimatedTotalFeesInToken,
1314
+ paymaster
1315
+ } = yield this.estimateSingleBatchPaymentGas({
1316
+ signerAddress,
1317
+ chainId,
1318
+ token: tokenSymbol,
1319
+ receivers,
1320
+ feeInclusive,
1321
+ totalAmount,
1322
+ walletClient
1323
+ });
1324
+ const amountToTransfer = feeInclusive ? totalAmount : feeExclusiveAmountInToken;
1325
+ const receiverAmount = feeInclusive ? feeInclusiveAmountInToken : totalAmount;
1326
+ yield viemClient.checkAndApproveToken(
1327
+ token2,
1328
+ smartAccountAddress,
1329
+ amountToTransfer * BigInt(paymentCount) + estimatedGasCostInToken * BigInt(2) * BigInt(paymentCount),
1330
+ allowMaxTokenApproval != null ? allowMaxTokenApproval : false
1331
+ );
1332
+ const amountExclusive = amountToTransfer + amountToTransfer / BigInt(2);
1333
+ const receiversAddress = receivers.map((r) => getAddress2(r.address));
1334
+ const callPolicy = toCallPolicy({
1335
+ policyVersion: CallPolicyVersion.V0_0_4,
1336
+ permissions: [
1337
+ {
1338
+ target: token2.address,
1339
+ valueLimit: BigInt(0),
1340
+ abi: parseAbi2(["function transferFrom(address,address,uint)"]),
1341
+ functionName: "transferFrom",
1342
+ args: [
1343
+ {
1344
+ condition: ParamCondition.EQUAL,
1345
+ value: getAddress2(signerAddress)
1346
+ },
1347
+ {
1348
+ condition: ParamCondition.ONE_OF,
1349
+ value: [
1350
+ "0x26eeCa5956Bf8C01040BAC9e6D7982a0e87F31B4",
1351
+ ...receiversAddress
1352
+ ]
1353
+ },
1354
+ {
1355
+ condition: ParamCondition.LESS_THAN_OR_EQUAL,
1356
+ value: amountExclusive
1357
+ }
1358
+ ]
1359
+ }
1360
+ ]
1361
+ });
1362
+ const permissionPlugin = yield toPermissionValidator(
1363
+ viemClient.publicClient(),
1364
+ {
1365
+ entryPoint,
1366
+ kernelVersion,
1367
+ signer: emptySessionKeySigner,
1368
+ policies: [callPolicy]
1369
+ }
1370
+ );
1371
+ const serializedSessionKeyAccount = yield createKernelAccount(
1372
+ viemClient.publicClient(),
1373
+ {
1374
+ entryPoint,
1375
+ kernelVersion,
1376
+ plugins: {
1377
+ sudo: ecdsaValidator,
1378
+ regular: permissionPlugin
1379
+ }
1380
+ }
1381
+ );
1382
+ const approval = yield serializePermissionAccount(
1383
+ serializedSessionKeyAccount
1384
+ );
1385
+ return { approval, amountExclusive };
1386
+ });
1387
+ }
1260
1388
  signRecurringTransactionCancellation(paymentCancellationParams) {
1261
1389
  return __async(this, null, function* () {
1262
1390
  var _a;
@@ -1504,6 +1632,23 @@ function executeSingleBatchPaymentAPICall(url, APIKey, userOperation, paymentPar
1504
1632
  return response.data;
1505
1633
  });
1506
1634
  }
1635
+ function executeScheduleBatchPaymentAPICall(url, APIKey, paymentParams, serviceParams) {
1636
+ return __async(this, null, function* () {
1637
+ const params = {
1638
+ paymentParams,
1639
+ serviceParams
1640
+ };
1641
+ const response = yield sendRequest({
1642
+ url,
1643
+ method: "post" /* Post */,
1644
+ body: params,
1645
+ headers: {
1646
+ "x-api-key": APIKey
1647
+ }
1648
+ });
1649
+ return response.data;
1650
+ });
1651
+ }
1507
1652
  function fetchRecurringTransactionWithId(url) {
1508
1653
  return __async(this, null, function* () {
1509
1654
  const response = yield sendRequest({ url, method: "get" /* Get */ });
@@ -2121,7 +2266,28 @@ import {
2121
2266
  toHex as toHex4,
2122
2267
  zeroAddress as zeroAddress5
2123
2268
  } from "viem";
2269
+ var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2124
2270
  var batchServiceUrl = "https://api.acta.link/batch/api/v1/";
2271
+ var transactionServiceTestUrl = "https://api.acta.link/transaction/test/v1/";
2272
+ var batchServiceTestUrl = "https://api.acta.link/batch/test/api/v1/";
2273
+ var returnEnvUrl = (chainId) => {
2274
+ const mainnetChain = mainnetChains.find((c) => c.id === chainId);
2275
+ const testnetChain = testnetChains.find((c) => c.id === chainId);
2276
+ if (!mainnetChain && !testnetChain) {
2277
+ throw new Error(`Chain ${chainId} not supported.`);
2278
+ }
2279
+ if (mainnetChain) {
2280
+ return {
2281
+ envTransactionServiceUrl: transactionServiceUrl3,
2282
+ envBatchServiceUrl: batchServiceUrl
2283
+ };
2284
+ } else {
2285
+ return {
2286
+ envTransactionServiceUrl: transactionServiceTestUrl,
2287
+ envBatchServiceUrl: batchServiceTestUrl
2288
+ };
2289
+ }
2290
+ };
2125
2291
  var ActaBatch = class {
2126
2292
  constructor(parameters) {
2127
2293
  this.APIkey = parameters.APIKey;
@@ -2142,8 +2308,9 @@ var ActaBatch = class {
2142
2308
  if (!instructionId || instructionId === "") {
2143
2309
  throw new Error("Instruction id is required");
2144
2310
  }
2311
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2145
2312
  const session = yield createBatchSessionAPICall(
2146
- `${batchServiceUrl}create/session`,
2313
+ `${envBatchServiceUrl}create/session`,
2147
2314
  this.APIkey,
2148
2315
  {
2149
2316
  name,
@@ -2175,8 +2342,9 @@ var ActaBatch = class {
2175
2342
  walletClient,
2176
2343
  instructionId
2177
2344
  } = parameters;
2345
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2178
2346
  const instuctionData = yield fetchBatchInstructionDetails(
2179
- `${batchServiceUrl}instruction/${instructionId}`,
2347
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2180
2348
  this.APIkey
2181
2349
  );
2182
2350
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2252,8 +2420,9 @@ var ActaBatch = class {
2252
2420
  allowMaxTokenApproval,
2253
2421
  instructionId
2254
2422
  } = params;
2423
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2255
2424
  const instuctionData = yield fetchBatchInstructionDetails(
2256
- `${batchServiceUrl}instruction/${instructionId}`,
2425
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2257
2426
  this.APIkey
2258
2427
  );
2259
2428
  if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
@@ -2296,7 +2465,7 @@ var ActaBatch = class {
2296
2465
  allowMaxTokenApproval
2297
2466
  });
2298
2467
  const txn = yield executeSingleBatchPaymentAPICall(
2299
- `${batchServiceUrl}execute/single/batch`,
2468
+ `${envBatchServiceUrl}execute/single/batch`,
2300
2469
  this.APIkey,
2301
2470
  rpcParameters,
2302
2471
  {
@@ -2319,6 +2488,98 @@ var ActaBatch = class {
2319
2488
  }
2320
2489
  });
2321
2490
  }
2491
+ createScheduleBatchPayment(params, serviceParams) {
2492
+ return __async(this, null, function* () {
2493
+ try {
2494
+ const {
2495
+ chainId,
2496
+ feeInclusive,
2497
+ signerAddress,
2498
+ token: tokenSymbol,
2499
+ walletClient,
2500
+ allowMaxTokenApproval,
2501
+ instructionId,
2502
+ executionTime
2503
+ } = params;
2504
+ const { envBatchServiceUrl } = returnEnvUrl(chainId);
2505
+ if (executionTime <= Date.now() + 1e3 * 60 * 2) {
2506
+ throw new Error(
2507
+ "Execution time must be more than 5 mins from current time."
2508
+ );
2509
+ }
2510
+ const instuctionData = yield fetchBatchInstructionDetails(
2511
+ `${envBatchServiceUrl}instruction/${instructionId}`,
2512
+ this.APIkey
2513
+ );
2514
+ if (instuctionData.receivers.length === 0 || instuctionData.receivers.length === void 0) {
2515
+ throw new Error("Instruction not found");
2516
+ }
2517
+ console.log(instuctionData);
2518
+ const tokenData = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
2519
+ if (!tokenData) {
2520
+ throw new Error("Token not supported");
2521
+ }
2522
+ const totalAmount = instuctionData.totalAmount;
2523
+ const totalAmountParsed = BigInt(
2524
+ parseUnits(totalAmount, tokenData.decimals)
2525
+ );
2526
+ const receivers = instuctionData.receivers.map(
2527
+ (i) => {
2528
+ const receiver = getAddress3(i.address);
2529
+ const tokenAmount = BigInt(parseUnits(i.amount, tokenData.decimals));
2530
+ return {
2531
+ address: receiver,
2532
+ amount: tokenAmount
2533
+ };
2534
+ }
2535
+ );
2536
+ const viemClient = new ViemClient(chainId, walletClient);
2537
+ const account = new ActaAccount(
2538
+ chainId,
2539
+ viemClient.publicClient(),
2540
+ walletClient
2541
+ );
2542
+ console.log("signing");
2543
+ const { amountExclusive, approval } = yield account.signRecurringOrScheduleBatchPayments({
2544
+ signerAddress,
2545
+ chainId,
2546
+ token: tokenSymbol,
2547
+ feeInclusive,
2548
+ receivers,
2549
+ totalAmount: totalAmountParsed,
2550
+ walletClient,
2551
+ allowMaxTokenApproval,
2552
+ count: 1
2553
+ });
2554
+ const txn = yield executeScheduleBatchPaymentAPICall(
2555
+ `${envBatchServiceUrl}execute/schedule/batch`,
2556
+ this.APIkey,
2557
+ {
2558
+ senderAddress: signerAddress,
2559
+ chainId,
2560
+ tokenAddress: tokenData.address,
2561
+ amount: toHex4(totalAmountParsed),
2562
+ feeInclusive,
2563
+ serviceType: "batch",
2564
+ amountExclusive: toHex4(amountExclusive),
2565
+ approval,
2566
+ executionAt: executionTime
2567
+ },
2568
+ {
2569
+ sessionId: serviceParams.sessionId
2570
+ }
2571
+ );
2572
+ console.log(txn);
2573
+ return txn.transaction.id;
2574
+ } catch (error) {
2575
+ console.log(error);
2576
+ if (error instanceof Error) {
2577
+ throw new Error(error.message);
2578
+ }
2579
+ throw new Error("Failed to create payment.");
2580
+ }
2581
+ });
2582
+ }
2322
2583
  };
2323
2584
 
2324
2585
  // src/utils.ts
@@ -2365,7 +2626,7 @@ import { coerce, gt } from "semver";
2365
2626
  var ECDSA_SIGNER_CONTRACT = "0x6A6F069E2a08c2468e7724Ab3250CdBFBA14D4FF";
2366
2627
  var billingServiceUrl = "https://api.acta.link/billing/v1/";
2367
2628
  var depositServiceUrl2 = "https://api.acta.link/deposit/v1/";
2368
- var transactionServiceUrl3 = "https://api.acta.link/transaction/v1/";
2629
+ var transactionServiceUrl4 = "https://api.acta.link/transaction/v1/";
2369
2630
  var toSignerId = (signer) => {
2370
2631
  return encodeAbiParameters(
2371
2632
  [{ name: "signerData", type: "bytes" }],
@@ -2764,7 +3025,7 @@ var cancelRecurringTransaction = (_0) => __async(null, [_0], function* ({
2764
3025
  });
2765
3026
  console.log(rpcParameters);
2766
3027
  const txn = yield cancelRecurringPaymentAPICall(
2767
- `${transactionServiceUrl3}execute/cancel`,
3028
+ `${transactionServiceUrl4}execute/cancel`,
2768
3029
  rpcParameters,
2769
3030
  {
2770
3031
  chainId,
@@ -2824,6 +3085,7 @@ export {
2824
3085
  ethereumUSDC,
2825
3086
  ethereumUSDT,
2826
3087
  ethereumWETH,
3088
+ executeScheduleBatchPaymentAPICall,
2827
3089
  executeSingleBatchPaymentAPICall,
2828
3090
  executeSinglePaymentAPICall,
2829
3091
  fetchBatchInstructionDetails,
@@ -2843,6 +3105,7 @@ export {
2843
3105
  lineaETH,
2844
3106
  lineaUSDC,
2845
3107
  lineaWETH,
3108
+ mainnetChains,
2846
3109
  optimismDAI,
2847
3110
  optimismETH,
2848
3111
  optimismUSDC,
@@ -2863,6 +3126,7 @@ export {
2863
3126
  serializePermissionAccountParams,
2864
3127
  supportedChains,
2865
3128
  supportedTokensByChain,
3129
+ testnetChains,
2866
3130
  toECDSASigner2 as toECDSASigner,
2867
3131
  toPermissionValidator2 as toPermissionValidator,
2868
3132
  toPolicyId,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actalink/commonlib",
3
- "version": "0.0.14",
3
+ "version": "0.0.15",
4
4
  "author": "Actalink",
5
5
  "license": "MIT license",
6
6
  "publishConfig": {