@actalink/commonlib 0.0.3 → 0.0.4

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
@@ -612,7 +612,6 @@ var import_viem6 = require("viem");
612
612
 
613
613
  // src/account.ts
614
614
  var import_viem4 = require("viem");
615
- var import_accounts3 = require("viem/accounts");
616
615
  var import_account_abstraction2 = require("viem/account-abstraction");
617
616
  var import_sdk2 = require("@zerodev/sdk");
618
617
  var import_constants = require("@zerodev/sdk/constants");
@@ -705,7 +704,7 @@ var ViemClient = class {
705
704
  signerAddress,
706
705
  spender
707
706
  );
708
- if (allowance < amount || allowMaxTokenApproval) {
707
+ if (allowance < amount) {
709
708
  const txn = yield this.walletClient.sendTransaction({
710
709
  to: token2.address,
711
710
  account: signerAddress,
@@ -1188,28 +1187,17 @@ var ActaAccount = class {
1188
1187
  to: (0, import_viem4.getAddress)(token2.address),
1189
1188
  abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1190
1189
  functionName: "transferFrom",
1191
- args: [fromAddress, smartAccountAddress, BigInt(0)]
1192
- },
1193
- {
1194
- to: (0, import_viem4.getAddress)(token2.address),
1195
- abi: (0, import_viem4.parseAbi)(["function approve(address,uint)"]),
1196
- functionName: "approve",
1197
- args: [paymaster, BigInt(0)]
1198
- },
1199
- {
1200
- to: (0, import_viem4.getAddress)(token2.address),
1201
- abi: (0, import_viem4.parseAbi)(["function transfer(address,uint)"]),
1202
- functionName: "transfer",
1203
1190
  args: [
1191
+ fromAddress,
1204
1192
  "0x061BA68bc8208F4AddBeE86F74F17D77129cCF70",
1205
1193
  BigInt(0)
1206
1194
  ]
1207
1195
  },
1208
1196
  {
1209
1197
  to: (0, import_viem4.getAddress)(token2.address),
1210
- abi: (0, import_viem4.parseAbi)(["function transfer(address,uint)"]),
1211
- functionName: "transfer",
1212
- args: [receiver, BigInt(0)]
1198
+ abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1199
+ functionName: "transferFrom",
1200
+ args: [fromAddress, receiver, BigInt(0)]
1213
1201
  }
1214
1202
  ]
1215
1203
  });
@@ -1292,33 +1280,19 @@ var ActaAccount = class {
1292
1280
  to: (0, import_viem4.getAddress)(token2.address),
1293
1281
  abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1294
1282
  functionName: "transferFrom",
1295
- args: [fromAddress, smartAccountAddress, amountToTransfer]
1296
- },
1297
- {
1298
- to: (0, import_viem4.getAddress)(token2.address),
1299
- abi: (0, import_viem4.parseAbi)(["function approve(address,uint)"]),
1300
- functionName: "approve",
1301
- args: [paymaster, estimatedGasCostInToken]
1302
- },
1303
- {
1304
- to: (0, import_viem4.getAddress)(token2.address),
1305
- abi: (0, import_viem4.parseAbi)(["function transfer(address,uint)"]),
1306
- functionName: "transfer",
1307
1283
  args: [
1284
+ fromAddress,
1308
1285
  "0x061BA68bc8208F4AddBeE86F74F17D77129cCF70",
1309
- ActalinkFeesInToken
1286
+ receiverAmount
1310
1287
  ]
1311
1288
  },
1312
1289
  {
1313
1290
  to: (0, import_viem4.getAddress)(token2.address),
1314
- abi: (0, import_viem4.parseAbi)(["function transfer(address,uint)"]),
1315
- functionName: "transfer",
1316
- args: [receiver, receiverAmount]
1291
+ abi: (0, import_viem4.parseAbi)(["function transferFrom(address,address,uint)"]),
1292
+ functionName: "transferFrom",
1293
+ args: [fromAddress, receiver, estimatedTotalFeesInToken]
1317
1294
  }
1318
- ],
1319
- paymasterContext: {
1320
- token: token2.address
1321
- }
1295
+ ]
1322
1296
  });
1323
1297
  const signature = yield account.signUserOperation(__spreadProps(__spreadValues({}, userOperation), {
1324
1298
  chainId: this.chainId
@@ -1373,11 +1347,6 @@ var ActaAccount = class {
1373
1347
  const smartAccountAddress = account.address;
1374
1348
  const viemClient = new ViemClient(this.chainId, this.signer);
1375
1349
  const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1376
- const sessionKeySigner = yield toECDSASigner(
1377
- (0, import_accounts3.privateKeyToAccount)(
1378
- "0x8519baaeb81ebbcf3597d93c2f9790d1eda37097121e844e1b88c1ab77b67ae2"
1379
- )
1380
- );
1381
1350
  const ecdsaValidator = yield (0, import_ecdsa_validator.signerToEcdsaValidator)(
1382
1351
  viemClient.publicClient(),
1383
1352
  {
@@ -1386,7 +1355,7 @@ var ActaAccount = class {
1386
1355
  signer: this.signer
1387
1356
  }
1388
1357
  );
1389
- const sessionKeyAddress = "0x0744F720fe178AC21F25a30263B6269a1C0bB106";
1358
+ const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1390
1359
  const emptyAccount = (0, import_sdk2.addressToEmptyAccount)(sessionKeyAddress);
1391
1360
  const emptySessionKeySigner = yield toECDSASigner(emptyAccount);
1392
1361
  const {
@@ -1426,45 +1395,13 @@ var ActaAccount = class {
1426
1395
  condition: import_policies2.ParamCondition.EQUAL,
1427
1396
  value: signerAddress
1428
1397
  },
1429
- {
1430
- condition: import_policies2.ParamCondition.EQUAL,
1431
- value: smartAccountAddress
1432
- },
1433
- {
1434
- condition: import_policies2.ParamCondition.GREATER_THAN_OR_EQUAL,
1435
- value: 0
1436
- }
1437
- ]
1438
- },
1439
- {
1440
- target: token2.address,
1441
- valueLimit: BigInt(0),
1442
- abi: (0, import_viem4.parseAbi)(["function approve(address,uint)"]),
1443
- functionName: "approve",
1444
- args: [
1445
- {
1446
- condition: import_policies2.ParamCondition.EQUAL,
1447
- value: paymaster
1448
- },
1449
- {
1450
- condition: import_policies2.ParamCondition.GREATER_THAN_OR_EQUAL,
1451
- value: 0
1452
- }
1453
- ]
1454
- },
1455
- {
1456
- target: token2.address,
1457
- valueLimit: BigInt(0),
1458
- abi: (0, import_viem4.parseAbi)(["function transfer(address,uint)"]),
1459
- functionName: "transfer",
1460
- args: [
1461
1398
  {
1462
1399
  condition: import_policies2.ParamCondition.ONE_OF,
1463
- value: ["0xbDCBee616C26D5282227a672C3d0B87EA477A3fe", receiver]
1400
+ value: ["0x061BA68bc8208F4AddBeE86F74F17D77129cCF70", receiver]
1464
1401
  },
1465
1402
  {
1466
- condition: import_policies2.ParamCondition.GREATER_THAN_OR_EQUAL,
1467
- value: 0
1403
+ condition: import_policies2.ParamCondition.LESS_THAN_OR_EQUAL,
1404
+ value: amountToTransfer + amountToTransfer / BigInt(2)
1468
1405
  }
1469
1406
  ]
1470
1407
  }
@@ -1921,6 +1858,38 @@ var ActaDeposit = class {
1921
1858
  return txn.recurringTransaction.id;
1922
1859
  });
1923
1860
  }
1861
+ getPaymentSteps() {
1862
+ return __async(this, null, function* () {
1863
+ const signerAddress = this.signerAddress;
1864
+ const chainId = this.chainId;
1865
+ const tokenSymbol = this.token;
1866
+ const amount = this.amount;
1867
+ const receiver = this.receiver;
1868
+ const feeInclusive = this.feeInclusive;
1869
+ const count = this.count;
1870
+ if (!signerAddress) return ["allowance", "confirm"];
1871
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1872
+ if (!token2) return ["allowance", "confirm"];
1873
+ const smartAccount = yield this.account.createAccount();
1874
+ const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
1875
+ chainId,
1876
+ amount,
1877
+ feeInclusive,
1878
+ receiver,
1879
+ signerAddress,
1880
+ token: tokenSymbol
1881
+ });
1882
+ const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1883
+ let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
1884
+ const allowance = yield this.viemClient.checkTokenAllowance(
1885
+ token2,
1886
+ signerAddress,
1887
+ smartAccount.address
1888
+ );
1889
+ if (paymentAmount <= allowance) return ["confirm"];
1890
+ return ["allowance", "confirm"];
1891
+ });
1892
+ }
1924
1893
  };
1925
1894
  // Annotate the CommonJS export names for ESM import in node:
1926
1895
  0 && (module.exports = {
package/dist/index.d.cts CHANGED
@@ -241,6 +241,7 @@ declare class ActaDeposit {
241
241
  createPayment(servicePaymentParams?: any): Promise<any>;
242
242
  createSinglePayment(servicePaymentParams?: any): Promise<any>;
243
243
  createRecurringPayments(servicePaymentParams?: any): Promise<any>;
244
+ getPaymentSteps(): Promise<string[]>;
244
245
  }
245
246
 
246
247
  declare class ActaAccount {
package/dist/index.d.ts CHANGED
@@ -241,6 +241,7 @@ declare class ActaDeposit {
241
241
  createPayment(servicePaymentParams?: any): Promise<any>;
242
242
  createSinglePayment(servicePaymentParams?: any): Promise<any>;
243
243
  createRecurringPayments(servicePaymentParams?: any): Promise<any>;
244
+ getPaymentSteps(): Promise<string[]>;
244
245
  }
245
246
 
246
247
  declare class ActaAccount {
package/dist/index.js CHANGED
@@ -525,7 +525,6 @@ import {
525
525
  getAddress as getAddress2,
526
526
  parseAbi as parseAbi2
527
527
  } from "viem";
528
- import { privateKeyToAccount as privateKeyToAccount2 } from "viem/accounts";
529
528
  import {
530
529
  createPaymasterClient,
531
530
  formatUserOperationRequest
@@ -627,7 +626,7 @@ var ViemClient = class {
627
626
  signerAddress,
628
627
  spender
629
628
  );
630
- if (allowance < amount || allowMaxTokenApproval) {
629
+ if (allowance < amount) {
631
630
  const txn = yield this.walletClient.sendTransaction({
632
631
  to: token2.address,
633
632
  account: signerAddress,
@@ -1144,28 +1143,17 @@ var ActaAccount = class {
1144
1143
  to: getAddress2(token2.address),
1145
1144
  abi: parseAbi2(["function transferFrom(address,address,uint)"]),
1146
1145
  functionName: "transferFrom",
1147
- args: [fromAddress, smartAccountAddress, BigInt(0)]
1148
- },
1149
- {
1150
- to: getAddress2(token2.address),
1151
- abi: parseAbi2(["function approve(address,uint)"]),
1152
- functionName: "approve",
1153
- args: [paymaster, BigInt(0)]
1154
- },
1155
- {
1156
- to: getAddress2(token2.address),
1157
- abi: parseAbi2(["function transfer(address,uint)"]),
1158
- functionName: "transfer",
1159
1146
  args: [
1147
+ fromAddress,
1160
1148
  "0x061BA68bc8208F4AddBeE86F74F17D77129cCF70",
1161
1149
  BigInt(0)
1162
1150
  ]
1163
1151
  },
1164
1152
  {
1165
1153
  to: getAddress2(token2.address),
1166
- abi: parseAbi2(["function transfer(address,uint)"]),
1167
- functionName: "transfer",
1168
- args: [receiver, BigInt(0)]
1154
+ abi: parseAbi2(["function transferFrom(address,address,uint)"]),
1155
+ functionName: "transferFrom",
1156
+ args: [fromAddress, receiver, BigInt(0)]
1169
1157
  }
1170
1158
  ]
1171
1159
  });
@@ -1248,33 +1236,19 @@ var ActaAccount = class {
1248
1236
  to: getAddress2(token2.address),
1249
1237
  abi: parseAbi2(["function transferFrom(address,address,uint)"]),
1250
1238
  functionName: "transferFrom",
1251
- args: [fromAddress, smartAccountAddress, amountToTransfer]
1252
- },
1253
- {
1254
- to: getAddress2(token2.address),
1255
- abi: parseAbi2(["function approve(address,uint)"]),
1256
- functionName: "approve",
1257
- args: [paymaster, estimatedGasCostInToken]
1258
- },
1259
- {
1260
- to: getAddress2(token2.address),
1261
- abi: parseAbi2(["function transfer(address,uint)"]),
1262
- functionName: "transfer",
1263
1239
  args: [
1240
+ fromAddress,
1264
1241
  "0x061BA68bc8208F4AddBeE86F74F17D77129cCF70",
1265
- ActalinkFeesInToken
1242
+ receiverAmount
1266
1243
  ]
1267
1244
  },
1268
1245
  {
1269
1246
  to: getAddress2(token2.address),
1270
- abi: parseAbi2(["function transfer(address,uint)"]),
1271
- functionName: "transfer",
1272
- args: [receiver, receiverAmount]
1247
+ abi: parseAbi2(["function transferFrom(address,address,uint)"]),
1248
+ functionName: "transferFrom",
1249
+ args: [fromAddress, receiver, estimatedTotalFeesInToken]
1273
1250
  }
1274
- ],
1275
- paymasterContext: {
1276
- token: token2.address
1277
- }
1251
+ ]
1278
1252
  });
1279
1253
  const signature = yield account.signUserOperation(__spreadProps(__spreadValues({}, userOperation), {
1280
1254
  chainId: this.chainId
@@ -1329,11 +1303,6 @@ var ActaAccount = class {
1329
1303
  const smartAccountAddress = account.address;
1330
1304
  const viemClient = new ViemClient(this.chainId, this.signer);
1331
1305
  const { paymasterClient, pimlicoClient } = yield this.createAccountHelpers();
1332
- const sessionKeySigner = yield toECDSASigner(
1333
- privateKeyToAccount2(
1334
- "0x8519baaeb81ebbcf3597d93c2f9790d1eda37097121e844e1b88c1ab77b67ae2"
1335
- )
1336
- );
1337
1306
  const ecdsaValidator = yield signerToEcdsaValidator(
1338
1307
  viemClient.publicClient(),
1339
1308
  {
@@ -1342,7 +1311,7 @@ var ActaAccount = class {
1342
1311
  signer: this.signer
1343
1312
  }
1344
1313
  );
1345
- const sessionKeyAddress = "0x0744F720fe178AC21F25a30263B6269a1C0bB106";
1314
+ const sessionKeyAddress = "0xFDEed8e268D74DF71f3Db7409F8A8290FF1263ED";
1346
1315
  const emptyAccount = addressToEmptyAccount(sessionKeyAddress);
1347
1316
  const emptySessionKeySigner = yield toECDSASigner(emptyAccount);
1348
1317
  const {
@@ -1382,45 +1351,13 @@ var ActaAccount = class {
1382
1351
  condition: ParamCondition.EQUAL,
1383
1352
  value: signerAddress
1384
1353
  },
1385
- {
1386
- condition: ParamCondition.EQUAL,
1387
- value: smartAccountAddress
1388
- },
1389
- {
1390
- condition: ParamCondition.GREATER_THAN_OR_EQUAL,
1391
- value: 0
1392
- }
1393
- ]
1394
- },
1395
- {
1396
- target: token2.address,
1397
- valueLimit: BigInt(0),
1398
- abi: parseAbi2(["function approve(address,uint)"]),
1399
- functionName: "approve",
1400
- args: [
1401
- {
1402
- condition: ParamCondition.EQUAL,
1403
- value: paymaster
1404
- },
1405
- {
1406
- condition: ParamCondition.GREATER_THAN_OR_EQUAL,
1407
- value: 0
1408
- }
1409
- ]
1410
- },
1411
- {
1412
- target: token2.address,
1413
- valueLimit: BigInt(0),
1414
- abi: parseAbi2(["function transfer(address,uint)"]),
1415
- functionName: "transfer",
1416
- args: [
1417
1354
  {
1418
1355
  condition: ParamCondition.ONE_OF,
1419
- value: ["0xbDCBee616C26D5282227a672C3d0B87EA477A3fe", receiver]
1356
+ value: ["0x061BA68bc8208F4AddBeE86F74F17D77129cCF70", receiver]
1420
1357
  },
1421
1358
  {
1422
- condition: ParamCondition.GREATER_THAN_OR_EQUAL,
1423
- value: 0
1359
+ condition: ParamCondition.LESS_THAN_OR_EQUAL,
1360
+ value: amountToTransfer + amountToTransfer / BigInt(2)
1424
1361
  }
1425
1362
  ]
1426
1363
  }
@@ -1877,6 +1814,38 @@ var ActaDeposit = class {
1877
1814
  return txn.recurringTransaction.id;
1878
1815
  });
1879
1816
  }
1817
+ getPaymentSteps() {
1818
+ return __async(this, null, function* () {
1819
+ const signerAddress = this.signerAddress;
1820
+ const chainId = this.chainId;
1821
+ const tokenSymbol = this.token;
1822
+ const amount = this.amount;
1823
+ const receiver = this.receiver;
1824
+ const feeInclusive = this.feeInclusive;
1825
+ const count = this.count;
1826
+ if (!signerAddress) return ["allowance", "confirm"];
1827
+ const token2 = getTokenByChainIdAndSymbol(chainId, tokenSymbol);
1828
+ if (!token2) return ["allowance", "confirm"];
1829
+ const smartAccount = yield this.account.createAccount();
1830
+ const { estimatedGasCostInToken, feeExclusiveAmountInToken } = yield this.account.estimateSinglePaymentGas({
1831
+ chainId,
1832
+ amount,
1833
+ feeInclusive,
1834
+ receiver,
1835
+ signerAddress,
1836
+ token: tokenSymbol
1837
+ });
1838
+ const amountToTransfer = feeInclusive ? amount : feeExclusiveAmountInToken;
1839
+ let paymentAmount = (amountToTransfer + estimatedGasCostInToken * BigInt(2)) * BigInt(count != null ? count : 1);
1840
+ const allowance = yield this.viemClient.checkTokenAllowance(
1841
+ token2,
1842
+ signerAddress,
1843
+ smartAccount.address
1844
+ );
1845
+ if (paymentAmount <= allowance) return ["confirm"];
1846
+ return ["allowance", "confirm"];
1847
+ });
1848
+ }
1880
1849
  };
1881
1850
  export {
1882
1851
  ActaAccount,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@actalink/commonlib",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "author": "Actalink",
5
5
  "license": "MIT license",
6
6
  "publishConfig": {